From 920a83be2650ed9e58adb9685dcfd215287571ad Mon Sep 17 00:00:00 2001 From: Julien Gomes Dias Date: Thu, 22 Dec 2022 16:39:12 +0100 Subject: [PATCH 1/4] [wip] ajout de keycloak --- roles/keycloak/.travis.yml | 29 +++++++++++ roles/keycloak/README.md | 38 ++++++++++++++ roles/keycloak/defaults/main.yml | 4 ++ roles/keycloak/files/docker-compose.yml | 62 ++++++++++++++++++++++ roles/keycloak/handlers/main.yml | 4 ++ roles/keycloak/meta/main.yml | 52 +++++++++++++++++++ roles/keycloak/tasks/install.yml | 68 +++++++++++++++++++++++++ roles/keycloak/tasks/main.yml | 6 +++ roles/keycloak/tasks/uninstall.yml | 7 +++ roles/keycloak/templates/env.j2 | 6 +++ roles/keycloak/tests/inventory | 2 + roles/keycloak/tests/test.yml | 5 ++ roles/keycloak/vars/main.yml | 4 ++ 13 files changed, 287 insertions(+) create mode 100644 roles/keycloak/.travis.yml create mode 100644 roles/keycloak/README.md create mode 100644 roles/keycloak/defaults/main.yml create mode 100644 roles/keycloak/files/docker-compose.yml create mode 100644 roles/keycloak/handlers/main.yml create mode 100644 roles/keycloak/meta/main.yml create mode 100644 roles/keycloak/tasks/install.yml create mode 100644 roles/keycloak/tasks/main.yml create mode 100644 roles/keycloak/tasks/uninstall.yml create mode 100644 roles/keycloak/templates/env.j2 create mode 100644 roles/keycloak/tests/inventory create mode 100644 roles/keycloak/tests/test.yml create mode 100644 roles/keycloak/vars/main.yml diff --git a/roles/keycloak/.travis.yml b/roles/keycloak/.travis.yml new file mode 100644 index 00000000..36bbf620 --- /dev/null +++ b/roles/keycloak/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/roles/keycloak/README.md b/roles/keycloak/README.md new file mode 100644 index 00000000..225dd44b --- /dev/null +++ b/roles/keycloak/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/keycloak/defaults/main.yml b/roles/keycloak/defaults/main.yml new file mode 100644 index 00000000..78b943ae --- /dev/null +++ b/roles/keycloak/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for loomio +site_name: Loomio +app_main_port: 28080 diff --git a/roles/keycloak/files/docker-compose.yml b/roles/keycloak/files/docker-compose.yml new file mode 100644 index 00000000..58bafa5c --- /dev/null +++ b/roles/keycloak/files/docker-compose.yml @@ -0,0 +1,62 @@ +version: '3.9' + +services: + keycloak: + depends_on: + - postgres + container_name: local_keycloak + environment: + DB_VENDOR: postgres + DB_ADDR: postgres + DB_DATABASE: ${POSTGRESQL_DB} + DB_USER: ${POSTGRESQL_USER} + DB_PASSWORD: ${POSTGRESQL_PASS} + image: jboss/keycloak:${KEYCLOAK_VERSION} + ports: + - "${PORT_KEYCLOAK}:8080" + restart: unless-stopped + networks: + - main + + postgres: + image: postgres:${POSTGRESQL_VERSION} + restart: unless-stopped + networks: + - main + env_file: ./.env + volumes: + - ./pgdata:/pgdata + - ./pgdumps:/pgdumps + environment: + PGDATA: /pgdata + POSTGRES_DB: ${POSTGRESQL_DB} + POSTGRES_USER: ${POSTGRESQL_USER} + POSTGRES_PASSWORD: ${POSTGRESQL_PASS} + + + pgbackups: + image: prodrigestivill/postgres-backup-local + restart: always + user: postgres:postgres + volumes: + - ./pgdumps:/backups + links: + - postgres + depends_on: + - postgres + environment: + - POSTGRES_HOST=postgres + - POSTGRES_DB=${POSTGRESQL_DB} + - POSTGRES_USER=${POSTGRESQL_USER} + - POSTGRES_PASSWORD=${POSTGRESQL_PASS} + - POSTGRES_EXTRA_OPTS=-Z6 --schema=public --blobs + - SCHEDULE=@daily + - BACKUP_KEEP_DAYS=7 + - BACKUP_KEEP_WEEKS=1 + - BACKUP_KEEP_MONTHS=1 + - HEALTHCHECK_PORT=8080 + + + +networks: + main: \ No newline at end of file diff --git a/roles/keycloak/handlers/main.yml b/roles/keycloak/handlers/main.yml new file mode 100644 index 00000000..d4732f93 --- /dev/null +++ b/roles/keycloak/handlers/main.yml @@ -0,0 +1,4 @@ +--- +# handlers file for keycloak +- name: reload nginx keycloak + service: name=nginx state=reloaded diff --git a/roles/keycloak/meta/main.yml b/roles/keycloak/meta/main.yml new file mode 100644 index 00000000..c572acc9 --- /dev/null +++ b/roles/keycloak/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/keycloak/tasks/install.yml b/roles/keycloak/tasks/install.yml new file mode 100644 index 00000000..5225d85a --- /dev/null +++ b/roles/keycloak/tasks/install.yml @@ -0,0 +1,68 @@ +--- +# tasks file for keycloak +- name: Create of update let'encrypt certificate + import_role: + name: _letsencrypt_certificate + when: app_domain is defined and app_domain != "" + +- name: create user {{ app_user }} + import_role: + name: _user + vars: + user_name: "{{ app_user }}" + user_password: "{{ app_user_password }}" + when: app_user is defined + +- name: "template nginx_app.j2 {{ app_instance_id }}" + template: + src: "nginx_app.j2" + dest: "/etc/nginx/sites-available/{{ app_instance_id }}.conf" + notify: reload nginx keycloak + tags: + - rev_proxy + +- name: "template nginx_app.j2 {{ app_instance_id }}" + template: + src: "nginx_channel_app.j2" + dest: "/etc/nginx/sites-available/channels_{{ app_instance_id }}.conf" + notify: reload nginx keycloak + tags: + - rev_proxy + +- name: "copy docker-compose {{ app_instance_id }}" + copy: + src: "docker-compose.yml" + dest: "{{ app_instance_root }}/docker-compose.yml" + tags: + - keycloak_installation + +- name: env file for keycloak + template: + src: "env.j2" + dest: "{{ app_instance_root }}/.env" + tags: + - keycloak_installation + +- name: "start keycloak - docker compose" + docker_compose: + project_src: "{{ app_instance_root }}" + state: present + tags: + - keycloak_installation + +- name: log rotate + import_role: + name: _app_logrotate + +- name: "enable site for {{ app_domain }}" + file: + state: link + path: "/etc/nginx/sites-enabled/{{ app_instance_id }}.conf" + src: "/etc/nginx/sites-available/{{ app_instance_id }}.conf" + notify: reload nginx keycloak + +- name: Add monit + import_role: + name: _app_monit + when: monit_request is defined and monit_request != '' + diff --git a/roles/keycloak/tasks/main.yml b/roles/keycloak/tasks/main.yml new file mode 100644 index 00000000..51621784 --- /dev/null +++ b/roles/keycloak/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- import_tasks: install.yml + when: app_run in ['install', 'reinstall'] + +- import_tasks: uninstall.yml + when: app_run == 'uninstall' diff --git a/roles/keycloak/tasks/uninstall.yml b/roles/keycloak/tasks/uninstall.yml new file mode 100644 index 00000000..c232149a --- /dev/null +++ b/roles/keycloak/tasks/uninstall.yml @@ -0,0 +1,7 @@ +--- +- name: "Stop keycloak - docker compose" + docker_compose: + project_src: "{{ app_instance_root }}" + state: absent + tags: + - keycloak_installation \ No newline at end of file diff --git a/roles/keycloak/templates/env.j2 b/roles/keycloak/templates/env.j2 new file mode 100644 index 00000000..23b3ef39 --- /dev/null +++ b/roles/keycloak/templates/env.j2 @@ -0,0 +1,6 @@ +KEYCLOAK_VERSION=20.0.2 +PORT_KEYCLOAK={{ app_main_port }} +POSTGRESQL_USER=keycloak +POSTGRESQL_PASS={{ db_pass }} +POSTGRESQL_DB=keycloak +POSTGRESQL_VERSION={{ postgresql_version }} \ No newline at end of file diff --git a/roles/keycloak/tests/inventory b/roles/keycloak/tests/inventory new file mode 100644 index 00000000..878877b0 --- /dev/null +++ b/roles/keycloak/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/keycloak/tests/test.yml b/roles/keycloak/tests/test.yml new file mode 100644 index 00000000..ce08a0ba --- /dev/null +++ b/roles/keycloak/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - keycloak diff --git a/roles/keycloak/vars/main.yml b/roles/keycloak/vars/main.yml new file mode 100644 index 00000000..eb947196 --- /dev/null +++ b/roles/keycloak/vars/main.yml @@ -0,0 +1,4 @@ +--- +# vars file for keycloak +app_user_home: "/home/{{ app_user }}" +app_instance_root: "{{ app_user_home }}/{{ app_instance_id }}" -- GitLab From 28da0f27fc5ddbb8e4c93ab6bdaad3139bdde303 Mon Sep 17 00:00:00 2001 From: Julien Gomes Dias Date: Thu, 22 Dec 2022 16:53:22 +0100 Subject: [PATCH 2/4] [wip] ajout du template pour nginx --- roles/keycloak/templates/nginx_app.j2 | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 roles/keycloak/templates/nginx_app.j2 diff --git a/roles/keycloak/templates/nginx_app.j2 b/roles/keycloak/templates/nginx_app.j2 new file mode 100644 index 00000000..4b34402a --- /dev/null +++ b/roles/keycloak/templates/nginx_app.j2 @@ -0,0 +1,67 @@ +map $http_user_agent $log_ua { + ~Monit 0; + default 1; +} + +server { + listen 80; + listen [::]:80; + server_name {{ app_domain | mandatory }}; + # enforce https + return 301 https://$server_name$request_uri; +} + +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + server_name {{ app_domain }}; + + ssl_certificate /etc/letsencrypt/live/{{ app_domain }}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/{{ app_domain }}/privkey.pem; + + # Add headers to serve security related headers + # Before enabling Strict-Transport-Security headers please read into this + # topic first. + # add_header Strict-Transport-Security "max-age=15768000; + # includeSubDomains; preload;"; + # + # WARNING: Only add the preload option once you read about + # the consequences in https://hstspreload.org/. This option + # will add the domain to a hardcoded list that is shipped + # in all major browsers and getting removed from this list + # could take several months. + + add_header X-Content-Type-Options nosniff; + add_header X-XSS-Protection "1; mode=block"; + add_header X-Robots-Tag all; # https://developers.google.com/search/docs/advanced/robots/robots_meta_tag + add_header X-Download-Options noopen; + add_header X-Permitted-Cross-Domain-Policies none; + add_header Strict-Transport-Security "max-age=15768000"; + + # Enable gzip but do not remove ETag headers + gzip on; + gzip_vary on; + gzip_comp_level 4; + gzip_min_length 256; + gzip_proxied expired no-cache no-store private no_last_modified no_etag auth; + gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; + + + access_log {{ www_log }}/{{ app_instance_id }}/access.log combined if=$log_ua; + error_log {{ www_log }}/{{ app_instance_id }}/error.log; + + # set max upload size + client_max_body_size 512M; + fastcgi_buffers 64 4K; + + + location / { + proxy_set_header HOST $host; + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + proxy_pass http://localhost:{{ app_main_port }}; + } + +} -- GitLab From 1eecb93c24707f7798460bfff331e11547e793e5 Mon Sep 17 00:00:00 2001 From: Admin paquerette Date: Fri, 23 Dec 2022 11:11:55 +0100 Subject: [PATCH 3/4] =?UTF-8?q?Divers=20corrections=20sur=20le=20r=C3=B4le?= =?UTF-8?q?s=20Keycloak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roles/keycloak/tasks/install.yml | 12 +++++------- roles/keycloak/templates/env.j2 | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/roles/keycloak/tasks/install.yml b/roles/keycloak/tasks/install.yml index 5225d85a..8f52e577 100644 --- a/roles/keycloak/tasks/install.yml +++ b/roles/keycloak/tasks/install.yml @@ -21,13 +21,11 @@ tags: - rev_proxy -- name: "template nginx_app.j2 {{ app_instance_id }}" - template: - src: "nginx_channel_app.j2" - dest: "/etc/nginx/sites-available/channels_{{ app_instance_id }}.conf" - notify: reload nginx keycloak - tags: - - rev_proxy +- name: Create a directory if it does not exist + file: + path: "{{ app_instance_root }}" + state: directory + mode: '0755' - name: "copy docker-compose {{ app_instance_id }}" copy: diff --git a/roles/keycloak/templates/env.j2 b/roles/keycloak/templates/env.j2 index 23b3ef39..afb36a05 100644 --- a/roles/keycloak/templates/env.j2 +++ b/roles/keycloak/templates/env.j2 @@ -1,6 +1,6 @@ -KEYCLOAK_VERSION=20.0.2 +KEYCLOAK_VERSION=latest PORT_KEYCLOAK={{ app_main_port }} POSTGRESQL_USER=keycloak POSTGRESQL_PASS={{ db_pass }} POSTGRESQL_DB=keycloak -POSTGRESQL_VERSION={{ postgresql_version }} \ No newline at end of file +POSTGRESQL_VERSION={{ postgresql_version }} -- GitLab From c750d00584a6e6ac3d2cf5a745de4e4cc1512697 Mon Sep 17 00:00:00 2001 From: Julien Gomes Dias Date: Thu, 9 Feb 2023 16:10:50 +0100 Subject: [PATCH 4/4] =?UTF-8?q?[fix]=20Correction=20dans=20le=20dockercomp?= =?UTF-8?q?ose=20pour=20que=20=C3=A7a=20fonctionne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roles/keycloak/defaults/main.yml | 3 ++- roles/keycloak/files/docker-compose.yml | 5 +++++ roles/keycloak/templates/env.j2 | 8 +++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/roles/keycloak/defaults/main.yml b/roles/keycloak/defaults/main.yml index 78b943ae..72b8d676 100644 --- a/roles/keycloak/defaults/main.yml +++ b/roles/keycloak/defaults/main.yml @@ -1,4 +1,5 @@ --- # defaults file for loomio -site_name: Loomio +site_name: keycloak app_main_port: 28080 +keycloak_version: latest \ No newline at end of file diff --git a/roles/keycloak/files/docker-compose.yml b/roles/keycloak/files/docker-compose.yml index 58bafa5c..db48da88 100644 --- a/roles/keycloak/files/docker-compose.yml +++ b/roles/keycloak/files/docker-compose.yml @@ -11,7 +11,11 @@ services: DB_DATABASE: ${POSTGRESQL_DB} DB_USER: ${POSTGRESQL_USER} DB_PASSWORD: ${POSTGRESQL_PASS} + KEYCLOAK_USER: ${KEYCLOAK_USER} + KEYCLOAK_PASSWORD: ${KEYCLOAK_PASSWORD} + PROXY_ADDRESS_FORWARDING: 'true' image: jboss/keycloak:${KEYCLOAK_VERSION} + env_file: ./.env ports: - "${PORT_KEYCLOAK}:8080" restart: unless-stopped @@ -38,6 +42,7 @@ services: image: prodrigestivill/postgres-backup-local restart: always user: postgres:postgres + env_file: ./.env volumes: - ./pgdumps:/backups links: diff --git a/roles/keycloak/templates/env.j2 b/roles/keycloak/templates/env.j2 index afb36a05..050d42a2 100644 --- a/roles/keycloak/templates/env.j2 +++ b/roles/keycloak/templates/env.j2 @@ -1,6 +1,8 @@ -KEYCLOAK_VERSION=latest +KEYCLOAK_VERSION={{ keycloak_version }} PORT_KEYCLOAK={{ app_main_port }} -POSTGRESQL_USER=keycloak +POSTGRESQL_USER={{ app_instance_id }}_usr POSTGRESQL_PASS={{ db_pass }} -POSTGRESQL_DB=keycloak +POSTGRESQL_DB={{ app_instance_id }}_db POSTGRESQL_VERSION={{ postgresql_version }} +KEYCLOAK_USER={{ admin_user }} +KEYCLOAK_PASSWORD={{ admin_pwd }} \ No newline at end of file -- GitLab