Skip to content

Commit 537128f

Browse files
committed
Updated the Postgres binary to use trustify image
Signed-off-by: mrrajan <86094767+mrrajan@users.noreply.github.com.>
1 parent dc342a6 commit 537128f

File tree

15 files changed

+299
-143
lines changed

15 files changed

+299
-143
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[*]
2+
end_of_line = lf
3+
insert_final_newline = true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ context/
2121
.vscode/
2222
.idea
2323
.ansible
24+
*.yml text eol=lf
25+
*.yaml text eol=lf

roles/tpa_single_node/tasks/importer/importer.yml

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
---
2-
- name: Copy create-importers.sql to Server
3-
ansible.builtin.copy:
4-
content: "{{ lookup('ansible.builtin.template', 'configs/create-importers.sql') }}"
5-
dest: "{{ tpa_single_node_config_dir }}/create-importers.sql"
6-
remote_src: true
2+
- name: Create configmap to create importers
3+
ansible.builtin.template:
4+
src: "{{ role_path }}/templates/manifests/init/create_importer/Configmap.yaml.j2"
5+
dest: "{{ tpa_single_node_kube_manifest_dir }}/ConfigMaps/create_importers.yaml"
76
mode: "0600"
7+
register: configmap_create_importers
88

9-
- name: Run create-importers.sql
10-
ansible.builtin.command: "psql postgresql://{{ tpa_single_node_pg_user }}:{{ tpa_single_node_pg_user_passwd }}@\
11-
{{ tpa_single_node_pg_host }}:{{ tpa_single_node_pg_port }}/{{ tpa_single_node_pg_db }}?sslmode={{ tpa_single_node_pg_ssl_mode }} \
12-
-v ON_ERROR_STOP=1 \
13-
-f {{ tpa_single_node_config_dir }}/create-importers.sql"
14-
changed_when: false
15-
no_log: true
16-
register: result
17-
retries: 2
18-
delay: 5
19-
until: result.rc == 0
9+
- name: Set configmaps to create importers
10+
ansible.builtin.set_fact:
11+
create_importers_configmaps: >-
12+
{{
13+
[
14+
tpa_single_node_kube_manifest_dir + '/ConfigMaps/create_importers.yaml'
15+
]
16+
}}
17+
18+
- name: Create importers
19+
ansible.builtin.include_tasks: install_manifest.yml
20+
vars:
21+
podman_spec:
22+
state: started
23+
systemd_file: create-importers
24+
network: "{{ tpa_single_node_podman_network }}"
25+
kube_file_content: "{{ lookup('ansible.builtin.template', 'manifests/init/create_importer/Deployment.yaml.j2') | from_yaml }}"
26+
configmaps: "{{ create_importers_configmaps }}"
2027

2128
- name: Set configmaps for importer
2229
ansible.builtin.set_fact:

roles/tpa_single_node/tasks/importer/importers.yml

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
---
2-
- name: Copy create-importers.sql to Server
3-
ansible.builtin.copy:
4-
content: "{{ lookup('ansible.builtin.template', 'configs/create-importers.sql') }}"
5-
dest: "{{ tpa_single_node_config_dir }}/create-importers.sql"
6-
remote_src: true
2+
- name: Create configmap to create importers
3+
ansible.builtin.template:
4+
src: "{{ role_path }}/templates/manifests/init/create_importer/Configmap.yaml.j2"
5+
dest: "{{ tpa_single_node_kube_manifest_dir }}/ConfigMaps/create_importers.yaml"
76
mode: "0600"
7+
register: configmap_create_importers
88

9-
- name: Run create-importers.sql
10-
ansible.builtin.command: "psql postgresql://{{ tpa_single_node_pg_user }}:{{ tpa_single_node_pg_user_passwd }}@\
11-
{{ tpa_single_node_pg_host }}:{{ tpa_single_node_pg_port }}/{{ tpa_single_node_pg_db }}?sslmode={{ tpa_single_node_pg_ssl_mode }} \
12-
-v ON_ERROR_STOP=1 \
13-
-f {{ tpa_single_node_config_dir }}/create-importers.sql"
14-
changed_when: false
15-
no_log: true
16-
register: result
17-
retries: 2
18-
delay: 5
19-
until: result.rc == 0
9+
- name: Set configmaps to create importers
10+
ansible.builtin.set_fact:
11+
create_importers_configmaps: >-
12+
{{
13+
[
14+
tpa_single_node_kube_manifest_dir + '/ConfigMaps/create_importers.yaml'
15+
]
16+
}}
17+
18+
- name: Create importers
19+
ansible.builtin.include_tasks: install_manifest.yml
20+
vars:
21+
podman_spec:
22+
state: started
23+
systemd_file: create-importers
24+
network: "{{ tpa_single_node_podman_network }}"
25+
kube_file_content: "{{ lookup('ansible.builtin.template', 'manifests/init/create_importer/Deployment.yaml.j2') | from_yaml }}"
26+
configmaps: "{{ create_importers_configmaps }}"
2027

2128
- name: Set configmaps for importers
2229
ansible.builtin.set_fact:
Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
---
2-
- name: Copy init-db.sql to Server
3-
ansible.builtin.copy:
4-
content: "{{ lookup('ansible.builtin.template', 'configs/init-db.sql') }}"
5-
dest: "{{ tpa_single_node_config_dir }}/init-db.sql"
6-
remote_src: true
2+
- name: Create configmap to create database
3+
ansible.builtin.template:
4+
src: "{{ role_path }}/templates/manifests/init/create_database/Configmap.yaml.j2"
5+
dest: "{{ tpa_single_node_kube_manifest_dir }}/ConfigMaps/create_database.yaml"
76
mode: "0600"
7+
register: configmap_create_db
88

9-
- name: Run init-db.sql
10-
ansible.builtin.command: "psql postgresql://{{ tpa_single_node_pg_admin }}:{{ tpa_single_node_pg_admin_passwd }}@\
11-
{{ tpa_single_node_pg_host }}:{{ tpa_single_node_pg_port }}/{{ tpa_single_node_pg_admin_db }}?sslmode={{ tpa_single_node_pg_ssl_mode }} \
12-
-v ON_ERROR_STOP=1 \
13-
-v db_name={{ tpa_single_node_pg_db }} \
14-
-v db_user={{ tpa_single_node_pg_user }} \
15-
-v db_password={{ tpa_single_node_pg_user_passwd }} \
16-
-f {{ tpa_single_node_config_dir }}/init-db.sql"
17-
changed_when: false
18-
no_log: true
9+
- name: Set configmaps to create database
10+
ansible.builtin.set_fact:
11+
create_db_configmaps: >-
12+
{{
13+
[
14+
tpa_single_node_kube_manifest_dir + '/ConfigMaps/create_database.yaml'
15+
]
16+
}}
1917
20-
- name: Testing DB to make sure it is available
21-
ansible.builtin.command: "psql postgresql://{{ tpa_single_node_pg_user }}:{{ tpa_single_node_pg_user_passwd }}@\
22-
{{ tpa_single_node_pg_host }}:{{ tpa_single_node_pg_port }}/{{ tpa_single_node_pg_db }}?sslmode={{ tpa_single_node_pg_ssl_mode }} -c 'SELECT 1'"
23-
register: select_output
24-
changed_when: false
25-
no_log: true
18+
- name: Create database
19+
ansible.builtin.include_tasks: install_manifest.yml
20+
vars:
21+
podman_spec:
22+
state: started
23+
systemd_file: create-db
24+
network: "{{ tpa_single_node_podman_network }}"
25+
kube_file_content: "{{ lookup('ansible.builtin.template', 'manifests/init/create_database/Deployment.yaml.j2') | from_yaml }}"
26+
configmaps: "{{ create_db_configmaps }}"

roles/tpa_single_node/tasks/infra/migrate-db.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
state: stopped
77
systemd_file: migrate-db
88
network: "{{ tpa_single_node_podman_network }}"
9-
kube_file_content: "{{ lookup('ansible.builtin.template', 'manifests/init/dataset/Deployment.yaml.j2') | from_yaml }}"
9+
kube_file_content: "{{ lookup('ansible.builtin.template', 'manifests/init/migrate_database/Deployment.yaml.j2') | from_yaml }}"
1010
# configmaps:
1111
# - "{{ tpa_single_node_kube_manifest_dir }}/ConfigMaps/custom-trust-anchor.yaml"

roles/tpa_single_node/tasks/os.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
---
2-
- name: Install repository key
3-
ansible.builtin.rpm_key:
4-
key: https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL
5-
state: present
6-
7-
- name: Install pgdg repository package
8-
ansible.builtin.dnf:
9-
name: https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
10-
state: present
11-
122
- name: Install podman-plugins package
133
ansible.builtin.package:
144
name: podman-plugins

roles/tpa_single_node/templates/configs/create-importers.sql

Lines changed: 0 additions & 39 deletions
This file was deleted.

roles/tpa_single_node/templates/configs/init-db.sql

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: create-db
5+
namespace: "{{ tpa_single_node_namespace }}"
6+
labels:
7+
app.kubernetes.io/name: create-db
8+
app.kubernetes.io/component: database
9+
app.kubernetes.io/instance: redhat-trusted-profile-analyzer
10+
app.kubernetes.io/version: 2.0.1
11+
data:
12+
init.sql: |
13+
-- ensure we have the database
14+
SELECT 'CREATE DATABASE ' || :'db_name'
15+
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = :'db_name')\gexec
16+
17+
-- create the user (if it doesn't exist)
18+
CREATE OR REPLACE FUNCTION add_user_if_not_exists(username NAME) RETURNS integer
19+
AS $$
20+
BEGIN
21+
IF NOT EXISTS (SELECT FROM pg_roles
22+
WHERE rolname = username) THEN
23+
24+
EXECUTE FORMAT('CREATE ROLE "%I" LOGIN', username);
25+
26+
END IF;
27+
RETURN NULL;
28+
END;
29+
$$ language plpgsql;
30+
31+
SELECT add_user_if_not_exists(:'db_user');
32+
33+
-- now set the password
34+
ALTER USER :db_user WITH PASSWORD :'db_password';
35+
36+
-- grant permission to connect
37+
GRANT CONNECT ON DATABASE :db_name TO :db_user;
38+
39+
-- grant permissions on database
40+
\connect :db_name
41+
42+
GRANT USAGE ON SCHEMA public TO :db_user;
43+
44+
-- grant on existing tables
45+
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO :db_user;
46+
47+
-- grant on future tables
48+
ALTER DEFAULT PRIVILEGES
49+
IN SCHEMA public
50+
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO :db_user;

0 commit comments

Comments
 (0)