Skip to content

Commit 7581ccf

Browse files
committed
Add frontends for advisor and vulnerability
1 parent a597433 commit 7581ccf

File tree

7 files changed

+282
-0
lines changed

7 files changed

+282
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
iop_advisor_frontend_container_image: "quay.io/iop/advisor-frontend"
3+
iop_advisor_frontend_container_tag: "foreman-3.16"
4+
iop_advisor_frontend_assets_path: "/var/lib/foreman/public/assets/apps/advisor"
5+
iop_advisor_frontend_source_path: "/srv/dist/."
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
- name: Create foreman user
3+
ansible.builtin.user:
4+
name: foreman
5+
state: present
6+
system: true
7+
shell: /sbin/nologin
8+
home: /var/lib/foreman
9+
create_home: true
10+
11+
- name: Pull Advisor Frontend container image
12+
containers.podman.podman_image:
13+
name: "{{ iop_advisor_frontend_container_image }}:{{ iop_advisor_frontend_container_tag }}"
14+
state: present
15+
16+
- name: Ensure assets directory exists
17+
ansible.builtin.file:
18+
path: "{{ iop_advisor_frontend_assets_path }}"
19+
state: directory
20+
owner: foreman
21+
group: foreman
22+
mode: '0755'
23+
24+
- name: Create temporary container for asset extraction
25+
containers.podman.podman_container:
26+
name: iop-advisor-frontend-temp
27+
image: "{{ iop_advisor_frontend_container_image }}:{{ iop_advisor_frontend_container_tag }}"
28+
state: created
29+
30+
- name: Extract advisor frontend assets from container
31+
containers.podman.podman_container_copy:
32+
container: iop-advisor-frontend-temp
33+
src: "{{ iop_advisor_frontend_source_path }}"
34+
dest: "{{ iop_advisor_frontend_assets_path }}"
35+
from_container: true
36+
37+
- name: Remove temporary container
38+
containers.podman.podman_container:
39+
name: iop-advisor-frontend-temp
40+
state: absent
41+
42+
- name: Set ownership of advisor frontend assets
43+
ansible.builtin.file:
44+
path: "{{ iop_advisor_frontend_assets_path }}"
45+
owner: foreman
46+
group: foreman
47+
recurse: true
48+
49+
- name: Set SELinux context for advisor frontend assets
50+
ansible.builtin.command:
51+
cmd: "chcon -R -t httpd_exec_t {{ iop_advisor_frontend_assets_path }}"
52+
changed_when: true
53+
54+
- name: Ensure Apache SSL config directory exists
55+
ansible.builtin.file:
56+
path: /etc/httpd/conf.d/05-foreman-ssl.d
57+
state: directory
58+
mode: '0755'
59+
60+
- name: Configure Apache for advisor frontend assets
61+
ansible.builtin.copy:
62+
dest: /etc/httpd/conf.d/05-foreman-ssl.d/advisor-frontend.conf
63+
content: |
64+
# IOP Advisor Frontend Assets Configuration
65+
Alias /assets/apps/advisor {{ iop_advisor_frontend_assets_path }}
66+
ProxyPass /assets/apps/advisor !
67+
68+
<LocationMatch "^/assets/apps/advisor">
69+
Options SymLinksIfOwnerMatch
70+
AllowOverride None
71+
Require all granted
72+
73+
# Use standard http expire header for assets instead of ETag
74+
<IfModule mod_expires.c>
75+
Header unset ETag
76+
FileETag None
77+
ExpiresActive On
78+
ExpiresDefault "access plus 1 year"
79+
</IfModule>
80+
81+
# Return compressed assets if they are precompiled
82+
RewriteEngine On
83+
# Make sure the browser supports gzip encoding and file with .gz added
84+
# does exist on disc before we rewrite with the extension
85+
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
86+
RewriteCond %{REQUEST_FILENAME} \.(css|js|svg)$
87+
RewriteCond %{REQUEST_FILENAME}.gz -s
88+
RewriteRule ^(.+) $1.gz [L]
89+
</LocationMatch>
90+
mode: '0644'
91+
notify: "httpd : Restart httpd"

src/roles/iop_core/tasks/main.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@
4646
- name: Deploy IOP Vulnerability service
4747
ansible.builtin.include_role:
4848
name: iop_vulnerability
49+
50+
- name: Deploy IOP Advisor Frontend
51+
ansible.builtin.include_role:
52+
name: iop_advisor_frontend
53+
54+
- name: Deploy IOP Vulnerability Frontend
55+
ansible.builtin.include_role:
56+
name: iop_vulnerability_frontend
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
iop_vulnerability_frontend_container_image: "quay.io/iop/vulnerability-frontend"
3+
iop_vulnerability_frontend_container_tag: "foreman-3.16"
4+
iop_vulnerability_frontend_assets_path: "/var/lib/foreman/public/assets/apps/vulnerability"
5+
iop_vulnerability_frontend_source_path: "/srv/dist/."
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
- name: Create foreman user
3+
ansible.builtin.user:
4+
name: foreman
5+
state: present
6+
system: true
7+
shell: /sbin/nologin
8+
home: /var/lib/foreman
9+
create_home: true
10+
11+
- name: Pull Vulnerability Frontend container image
12+
containers.podman.podman_image:
13+
name: "{{ iop_vulnerability_frontend_container_image }}:{{ iop_vulnerability_frontend_container_tag }}"
14+
state: present
15+
16+
- name: Ensure assets directory exists
17+
ansible.builtin.file:
18+
path: "{{ iop_vulnerability_frontend_assets_path }}"
19+
state: directory
20+
owner: foreman
21+
group: foreman
22+
mode: '0755'
23+
24+
- name: Create temporary container for asset extraction
25+
containers.podman.podman_container:
26+
name: iop-vulnerability-frontend-temp
27+
image: "{{ iop_vulnerability_frontend_container_image }}:{{ iop_vulnerability_frontend_container_tag }}"
28+
state: created
29+
30+
- name: Extract vulnerability frontend assets from container
31+
containers.podman.podman_container_copy:
32+
container: iop-vulnerability-frontend-temp
33+
src: "{{ iop_vulnerability_frontend_source_path }}"
34+
dest: "{{ iop_vulnerability_frontend_assets_path }}"
35+
from_container: true
36+
37+
- name: Remove temporary container
38+
containers.podman.podman_container:
39+
name: iop-vulnerability-frontend-temp
40+
state: absent
41+
42+
- name: Set ownership of vulnerability frontend assets
43+
ansible.builtin.file:
44+
path: "{{ iop_vulnerability_frontend_assets_path }}"
45+
owner: foreman
46+
group: foreman
47+
recurse: true
48+
49+
- name: Set SELinux context for vulnerability frontend assets
50+
ansible.builtin.command:
51+
cmd: "chcon -R -t httpd_exec_t {{ iop_vulnerability_frontend_assets_path }}"
52+
changed_when: true
53+
54+
- name: Ensure Apache SSL config directory exists
55+
ansible.builtin.file:
56+
path: /etc/httpd/conf.d/05-foreman-ssl.d
57+
state: directory
58+
mode: '0755'
59+
60+
- name: Configure Apache for vulnerability frontend assets
61+
ansible.builtin.copy:
62+
dest: /etc/httpd/conf.d/05-foreman-ssl.d/vulnerability-frontend.conf
63+
content: |
64+
# IOP Vulnerability Frontend Assets Configuration
65+
Alias /assets/apps/vulnerability {{ iop_vulnerability_frontend_assets_path }}
66+
ProxyPass /assets/apps/vulnerability !
67+
68+
<LocationMatch "^/assets/apps/vulnerability">
69+
Options SymLinksIfOwnerMatch
70+
AllowOverride None
71+
Require all granted
72+
73+
# Use standard http expire header for assets instead of ETag
74+
<IfModule mod_expires.c>
75+
Header unset ETag
76+
FileETag None
77+
ExpiresActive On
78+
ExpiresDefault "access plus 1 year"
79+
</IfModule>
80+
81+
# Return compressed assets if they are precompiled
82+
RewriteEngine On
83+
# Make sure the browser supports gzip encoding and file with .gz added
84+
# does exist on disc before we rewrite with the extension
85+
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
86+
RewriteCond %{REQUEST_FILENAME} \.(css|js|svg)$
87+
RewriteCond %{REQUEST_FILENAME}.gz -s
88+
RewriteRule ^(.+) $1.gz [L]
89+
</LocationMatch>
90+
mode: '0644'
91+
notify: "httpd : Restart httpd"

tests/iop/test_advisor_frontend.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import pytest
2+
3+
4+
def test_advisor_frontend_assets_directory(server):
5+
assets_dir = server.file("/var/lib/foreman/public/assets/apps/advisor")
6+
assert assets_dir.exists
7+
assert assets_dir.is_directory
8+
assert assets_dir.mode == 0o755
9+
10+
11+
def test_advisor_frontend_assets_ownership(server):
12+
assets_dir = server.file("/var/lib/foreman/public/assets/apps/advisor")
13+
assert assets_dir.user == "foreman"
14+
assert assets_dir.group == "foreman"
15+
16+
17+
def test_advisor_frontend_app_info_file(server):
18+
app_info_file = server.file("/var/lib/foreman/public/assets/apps/advisor/app.info.json")
19+
20+
assert app_info_file.exists
21+
assert app_info_file.is_file
22+
assert app_info_file.user == "foreman"
23+
assert app_info_file.group == "foreman"
24+
25+
26+
def test_advisor_frontend_asset_accessible_via_https(server):
27+
result = server.run("curl -s -o /dev/null -w '%{http_code}' -k https://localhost/assets/apps/advisor/ 2>/dev/null || echo '000'")
28+
assert result.succeeded
29+
http_code = result.stdout.strip()
30+
assert http_code != "000"
31+
assert http_code in ["200", "301", "302", "403"]
32+
33+
34+
def test_advisor_frontend_static_file_content_type(server):
35+
result = server.run("curl -s -I http://localhost/assets/apps/advisor/ 2>/dev/null | grep -i 'content-type' || echo 'no-content-type'")
36+
assert result.succeeded
37+
assert "no-content-type" not in result.stdout
38+
assert "content-type" in result.stdout.lower()
39+
40+
41+
def test_advisor_frontend_javascript_assets_accessible(server):
42+
result = server.run("find /var/lib/foreman/public/assets/apps/advisor -name '*.js' | head -1")
43+
assert result.succeeded
44+
assert result.stdout.strip()
45+
js_file = result.stdout.strip().replace("/var/lib/foreman/public", "")
46+
curl_result = server.run(f"curl -s -o /dev/null -w '%{{http_code}}' -k https://localhost{js_file} 2>/dev/null || echo '000'")
47+
assert curl_result.succeeded
48+
http_code = curl_result.stdout.strip()
49+
assert http_code in ["200", "403", "404"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
3+
4+
def test_vulnerability_frontend_assets_directory(server):
5+
assets_dir = server.file("/var/lib/foreman/public/assets/apps/vulnerability")
6+
assert assets_dir.exists
7+
assert assets_dir.is_directory
8+
assert assets_dir.mode == 0o755
9+
10+
11+
def test_vulnerability_frontend_assets_ownership(server):
12+
assets_dir = server.file("/var/lib/foreman/public/assets/apps/vulnerability")
13+
assert assets_dir.user == "foreman"
14+
assert assets_dir.group == "foreman"
15+
16+
17+
def test_vulnerability_frontend_app_info_file(server):
18+
app_info_file = server.file("/var/lib/foreman/public/assets/apps/vulnerability/app.info.json")
19+
assert app_info_file.exists
20+
assert app_info_file.is_file
21+
assert app_info_file.user == "foreman"
22+
assert app_info_file.group == "foreman"
23+
24+
25+
def test_vulnerability_frontend_javascript_assets_accessible(server):
26+
result = server.run("find /var/lib/foreman/public/assets/apps/vulnerability -name '*.js' | head -1")
27+
assert result.succeeded
28+
assert result.stdout.strip()
29+
js_file = result.stdout.strip().replace("/var/lib/foreman/public", "")
30+
curl_result = server.run(f"curl -s -o /dev/null -w '%{{http_code}}' -k https://localhost{js_file}")
31+
assert curl_result.succeeded
32+
http_code = curl_result.stdout.strip()
33+
assert http_code in ["200"]

0 commit comments

Comments
 (0)