Skip to content
Snippets Groups Projects
Commit 1b07d030 authored by ale's avatar ale
Browse files

Add support for an API proxy

parent 385c5a8f
No related branches found
No related tags found
1 merge request!311Add support for an API proxy
...@@ -2088,6 +2088,12 @@ using single sign-on, allowing access only to administrators (members ...@@ -2088,6 +2088,12 @@ using single sign-on, allowing access only to administrators (members
of the *admins* group). This is quite useful for admin web interfaces of the *admins* group). This is quite useful for admin web interfaces
of internal services that do not support SSO integration of their own. of internal services that do not support SSO integration of their own.
`enable_api_proxy`: If true, place the service behind authentication
using a mechanism more appropriate for non-interactive APIs (HTTP
Basic Authentication using Application-Specific Passwords). Only members
of the *admins* group will have access. When this option is set, you
also need to specify a unique `auth_service` to be used for ASPs.
#### HTTP (All domains) #### HTTP (All domains)
`horizontal_endpoints`: List of HTTP endpoints exported by the `horizontal_endpoints`: List of HTTP endpoints exported by the
......
No preview for this file type
...@@ -332,6 +332,7 @@ def _build_public_endpoints_map(services): ...@@ -332,6 +332,7 @@ def _build_public_endpoints_map(services):
'name': upstream_name, 'name': upstream_name,
'service_name': service_name, 'service_name': service_name,
'port': pe['port'], 'port': pe['port'],
'enable_api_proxy': pe.get('enable_api_proxy', False),
'enable_sso_proxy': pe.get('enable_sso_proxy', False), 'enable_sso_proxy': pe.get('enable_sso_proxy', False),
'sharded': pe.get('sharded', False), 'sharded': pe.get('sharded', False),
} }
...@@ -385,6 +386,7 @@ def _build_horizontal_upstreams_map(services): ...@@ -385,6 +386,7 @@ def _build_horizontal_upstreams_map(services):
'name': upstream_name, 'name': upstream_name,
'service_name': service_name, 'service_name': service_name,
'port': ep['port'], 'port': ep['port'],
'enable_api_proxy': False,
'enable_sso_proxy': False, 'enable_sso_proxy': False,
'sharded': False, 'sharded': False,
} }
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
- name: restart sso-proxy - name: restart sso-proxy
systemd: name=sso-proxy.service state=restarted enabled=yes masked=no systemd: name=sso-proxy.service state=restarted enabled=yes masked=no
- name: restart api-proxy
systemd: name=api-proxy.service state=restarted enabled=yes masked=no
- name: reload firewall - name: reload firewall
systemd: systemd:
name: firewall.service name: firewall.service
......
---
- set_fact:
api_proxy_auth_services: "{{ services.values() | selectattr('public_endpoints', 'defined') | map(attribute='public_endpoints') | flatten | selectattr('enable_api_proxy', 'defined') | selectattr('enable_api_proxy') | map(attribute='auth_service') }}"
- name: Configure api-proxy auth services
copy:
dest: "/etc/auth-server/services.d/api-proxy.yml"
content: |
{% for s in api_proxy_auth_services %}
{{ s }}:
backends:
- backend: file
params:
src: users.yml
static_groups: [admins]
enforce_2fa: true
rate_limits:
- ip_ratelimit
- failed_login_blacklist
- anti_bruteforce_blacklist
{% endfor %}
when: "api_proxy_auth_services"
...@@ -3,3 +3,7 @@ ...@@ -3,3 +3,7 @@
# Only set up nginx if there are public_endpoints defined. # Only set up nginx if there are public_endpoints defined.
- import_tasks: nginx.yml - import_tasks: nginx.yml
when: float_enable_http_frontend when: float_enable_http_frontend
- import_tasks: api-proxy.yml
when: float_enable_http_frontend
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
state: present state: present
vars: vars:
packages: packages:
- api-proxy
- sso-proxy - sso-proxy
- nginx-full - nginx-full
- libnginx-mod-http-headers-more-filter - libnginx-mod-http-headers-more-filter
...@@ -17,20 +18,32 @@ ...@@ -17,20 +18,32 @@
dest: /etc/default/sso-proxy dest: /etc/default/sso-proxy
notify: restart sso-proxy notify: restart sso-proxy
- name: Configure ssoproxy - name: Configure sso-proxy
template: template:
src: proxy.yml.j2 src: sso-proxy.yml.j2
dest: /etc/sso/proxy.yml dest: /etc/sso/proxy.yml
owner: root owner: root
group: sso-proxy group: sso-proxy
mode: 0640 mode: 0640
notify: restart sso-proxy notify: restart sso-proxy
- name: Add user sso-proxy to credentials group - name: Configure api-proxy
template:
src: api-proxy.yml.j2
dest: /etc/api-proxy.yml
owner: root
group: api-proxy
mode: 0640
notify: restart api-proxy
- name: Add proxy users to credentials group
user: user:
name: sso-proxy name: "{{ item }}"
groups: ssoproxy-credentials groups: ssoproxy-credentials
append: yes append: yes
loop:
- api-proxy
- sso-proxy
- name: Enable sso-proxy systemd unit - name: Enable sso-proxy systemd unit
systemd: systemd:
......
---
backends:
{% for service in services.values() -%}
{% for endpoint in service.get('public_endpoints', []) -%}
{% if endpoint.get('enable_api_proxy') %}
- host: "{{ endpoint.name }}.{{ domain_public[0] }}"
{% if endpoint.get('scheme') == 'https' %}
tls_server_name: "{{ service.name }}.{{ domain }}"
client_tls:
cert: "/etc/credentials/x509/ssoproxy/client/cert.pem"
key: "/etc/credentials/x509/ssoproxy/client/private_key.pem"
ca: "/etc/credentials/x509/ssoproxy/ca.pem"
{% endif %}
upstream:
- {{ service.name }}.{{ domain }}:{{ endpoint.port }}
auth_service: "{{ endpoint.auth_service }}"
allowed_groups:
{% for group in endpoint.get('allowed_groups', ['admins']) %}
- {{ group }}
{% endfor %}
{% endif -%}
{% endfor -%}
{% endfor %}
...@@ -5,6 +5,11 @@ upstream {{ upstream.name }}{% if shard %}_{{ shard }}{% endif %} { ...@@ -5,6 +5,11 @@ upstream {{ upstream.name }}{% if shard %}_{{ shard }}{% endif %} {
Talk directly to the SSO proxy on localhost. Talk directly to the SSO proxy on localhost.
#} #}
server 127.0.0.1:5003; server 127.0.0.1:5003;
{% elif upstream.enable_api_proxy | default(False) %}
{#
Talk directly to the api-proxy on localhost.
#}
server 127.0.0.1:5009;
{% else %} {% else %}
{# {#
Use the internal endpoint name, which resolves to multiple IP Use the internal endpoint name, which resolves to multiple IP
......
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
location {{ pe_config.path }} { location {{ pe_config.path }} {
include /etc/nginx/snippets/block.conf; include /etc/nginx/snippets/block.conf;
include /etc/nginx/snippets/proxy.conf; include /etc/nginx/snippets/proxy.conf;
{% if not upstream.enable_sso_proxy and pe_config.get('scheme', 'https') == 'https' %} {% if not upstream.enable_sso_proxy and not upstream.enable_api_proxy and pe_config.get('scheme', 'https') == 'https' %}
proxy_pass https://{{ pe_config.float_upstream_name }}{% if upstream.sharded and shard %}_{{ shard }}{% endif %}; proxy_pass https://{{ pe_config.float_upstream_name }}{% if upstream.sharded and shard %}_{{ shard }}{% endif %};
include /etc/nginx/snippets/proxy-ssl.conf; include /etc/nginx/snippets/proxy-ssl.conf;
proxy_ssl_name {{ upstream.service_name }}.{{ domain }}; proxy_ssl_name {{ upstream.service_name }}.{{ domain }};
{% else %} {% else %}
proxy_pass http://{{ pe_config.float_upstream_name }}{% if upstream.sharded and shard %}_{{ shard }}{% endif %}; proxy_pass http://{{ pe_config.float_upstream_name }}{% if upstream.sharded and shard %}_{{ shard }}{% endif %};
{% endif %} {% endif %}
{% if not upstream.enable_sso_proxy %} {% if not upstream.enable_sso_proxy and not upstream.enable_api_proxy %}
proxy_cache global; proxy_cache global;
{% endif %} {% endif %}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment