-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Wolfgang Kulhanek <[email protected]>
- Loading branch information
Showing
12 changed files
with
285 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...le/roles_ocp_workloads/ocp4_workload_deploy_hosted_cluster/tasks/setup_authentication.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
- name: Generate admin user password | ||
when: ocp4_workload_deploy_hosted_cluster_admin_password | default('') | length == 0 | ||
ansible.builtin.set_fact: | ||
_ocp4_workload_deploy_hosted_cluster_admin_password: >- | ||
{{ lookup('password', '/dev/null chars=ascii_letters,digits ' | ||
~ 'length=' ~ ocp4_workload_deploy_hosted_cluster_admin_password_length | ||
) }} | ||
- name: Use provided admin password | ||
when: ocp4_workload_deploy_hosted_cluster_admin_password | default('') | length > 0 | ||
ansible.builtin.set_fact: | ||
_ocp4_workload_deploy_hosted_cluster_admin_password: "{{ ocp4_workload_deploy_hosted_cluster_admin_password }}" | ||
|
||
- name: Generate htpasswd hash for admin user | ||
ansible.builtin.shell: >- | ||
htpasswd -nb "admin" "{{ _ocp4_workload_deploy_hosted_cluster_admin_password }}" | cut -d: -f2 | ||
register: r_htpasswd_admin_line | ||
|
||
- name: Set htpasswd admin password hash | ||
when: r_htpasswd_admin_line is succeeded | ||
ansible.builtin.set_fact: | ||
_ocp4_workload_deploy_hosted_cluster_admin_password_hash: "{{ r_htpasswd_admin_line.stdout }}" | ||
|
||
- name: Generate user passwords | ||
when: ocp4_workload_deploy_hosted_cluster_user_password | default('') | length == 0 | ||
ansible.builtin.set_fact: | ||
_ocp4_workload_deploy_hosted_cluster_user_password: >- | ||
{{ lookup('password', '/dev/null chars=ascii_letters,digits ' | ||
~ 'length=' ~ ocp4_workload_deploy_hosted_cluster_user_password_length | ||
) }} | ||
- name: Use provided user passwords | ||
when: ocp4_workload_deploy_hosted_cluster_user_password | default('') | length > 0 | ||
ansible.builtin.set_fact: | ||
_ocp4_workload_deploy_hosted_cluster_user_password: "{{ ocp4_workload_deploy_hosted_cluster_user_password }}" | ||
|
||
- name: Generate htpasswd hash for user passwords | ||
ansible.builtin.shell: >- | ||
htpasswd -nb "userN" "{{ _ocp4_workload_deploy_hosted_cluster_user_password }}" | cut -d: -f2 | ||
register: r_htpasswd_user_line | ||
|
||
- name: Set htpasswd user password hash | ||
when: r_htpasswd_user_line is succeeded | ||
ansible.builtin.set_fact: | ||
_ocp4_workload_deploy_hosted_cluster_user_password_hash: "{{ r_htpasswd_user_line.stdout }}" | ||
|
||
- name: Generate htpasswd file | ||
ansible.builtin.template: | ||
src: htpasswd.j2 | ||
dest: /home/opentlc-mgr/users.htpasswd | ||
owner: opentlc-mgr | ||
mode: 0664 | ||
|
||
- name: Read contents of htpasswd file | ||
ansible.builtin.slurp: | ||
src: /home/opentlc-mgr/users.htpasswd | ||
register: r_htpasswd_file | ||
|
||
- name: Remove generated htpasswd file | ||
ansible.builtin.file: | ||
path: /home/opentlc-mgr/users.htpasswd | ||
state: absent | ||
|
||
- name: Ensure secret htpasswd-{{ guid }} is absent | ||
kubernetes.core.k8s: | ||
state: absent | ||
api_version: v1 | ||
kind: Secret | ||
name: "htpasswd-{{ guid }}" | ||
namespace: local-cluster | ||
register: r_htpasswd_secret_absent | ||
retries: 5 | ||
delay: 10 | ||
until: r_htpasswd_secret_absent is success | ||
|
||
- name: Create secret htpasswd-{{ guid }} | ||
kubernetes.core.k8s: | ||
state: present | ||
definition: "{{ lookup('template', 'secret-htpasswd.yaml.j2' ) | from_yaml }}" |
32 changes: 32 additions & 0 deletions
32
...roles_ocp_workloads/ocp4_workload_deploy_hosted_cluster/tasks/setup_oauth_certificate.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
- name: Get the IngressController definition from hub cluster | ||
kubernetes.core.k8s_info: | ||
api_version: operator.openshift.io/v1 | ||
kind: IngressController | ||
name: default | ||
namespace: openshift-ingress-operator | ||
register: r_ingresscontroller | ||
|
||
- name: Determine if the hub cluster has certificates installed | ||
when: | ||
- r_ingresscontroller.resources | length == 1 | ||
- r_ingresscontroller.resources[0].spec.defaultCertificate is defined | ||
- r_ingresscontroller.resources[0].spec.defaultCertificate.name is defined | ||
block: | ||
- name: Retrieve current ingress controller certificate | ||
kubernetes.core.k8s_info: | ||
api_version: v1 | ||
kind: Secret | ||
name: "{{ r_ingresscontroller.resources[0].spec.defaultCertificate.name }}" | ||
namespace: openshift-ingress | ||
register: r_ingresscontroller_cert | ||
|
||
- name: Create secret oauth-{{ guid }} | ||
when: | ||
- r_ingresscontroller_cert.resources | length == 1 | ||
- r_ingresscontroller_cert.resources[0].data is defined | ||
- r_ingresscontroller_cert.resources[0].data['tls.key'] is defined | ||
- r_ingresscontroller_cert.resources[0].data['tls.crt'] is defined | ||
kubernetes.core.k8s: | ||
state: present | ||
definition: "{{ lookup('template', 'secret-oauth.yaml.j2' ) | from_yaml }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...kloads/ocp4_workload_deploy_hosted_cluster/templates/certmanager/placementbinding.yaml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: PlacementBinding | ||
metadata: | ||
name: cert-{{ guid }} | ||
namespace: rhdp-policies | ||
placementRef: | ||
apiGroup: apps.open-cluster-management.io | ||
kind: PlacementRule | ||
name: cert-{{ guid }} | ||
subjects: | ||
- apiGroup: policy.open-cluster-management.io | ||
kind: Policy | ||
name: cert-{{ guid }} |
14 changes: 14 additions & 0 deletions
14
...workloads/ocp4_workload_deploy_hosted_cluster/templates/certmanager/placementrule.yaml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
apiVersion: apps.open-cluster-management.io/v1 | ||
kind: PlacementRule | ||
metadata: | ||
name: cert-{{ guid }} | ||
namespace: rhdp-policies | ||
spec: | ||
clusterSelector: | ||
matchLabels: | ||
name: {{ ocp4_workload_deploy_hosted_cluster_name }} | ||
vendor: OpenShift | ||
{% if ocp4_workload_deploy_hosted_cluster_labels | default("") | length > 0 %} | ||
{{ ocp4_workload_deploy_hosted_cluster_labels | to_nice_yaml | indent(6) }} | ||
{% endif %} |
73 changes: 73 additions & 0 deletions
73
...es_ocp_workloads/ocp4_workload_deploy_hosted_cluster/templates/certmanager/policy.yaml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: Policy | ||
metadata: | ||
name: cert-{{ guid }} | ||
namespace: rhdp-policies | ||
spec: | ||
remediationAction: enforce | ||
disabled: false | ||
policy-templates: | ||
- objectDefinition: | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: ConfigurationPolicy | ||
metadata: | ||
name: cert-{{ guid }} | ||
spec: | ||
remediationAction: enforce | ||
severity: medium | ||
object-templates: | ||
- complianceType: musthave | ||
objectDefinition: | ||
apiVersion: cert-manager.io/v1 | ||
kind: ClusterIssuer | ||
metadata: | ||
name: letsencrypt-production-route53 | ||
spec: | ||
acme: | ||
email: [email protected] | ||
server: https://acme-v02.api.letsencrypt.org/directory | ||
privateKeySecretRef: | ||
name: cluster-issuer-le-production | ||
solvers: | ||
- selector: | ||
dnsZones: | ||
- {{ ocp4_workload_deploy_hosted_cluster_base_domain }} | ||
dns01: | ||
route53: | ||
region: {{ ocp4_workload_deploy_hosted_cluster_certmanager_aws_region }} | ||
hostedZoneID: {{ ocp4_workload_deploy_hosted_cluster_certmanager_aws_hostedzone_id }} | ||
accessKeyID: {{ ocp4_workload_deploy_hosted_cluster_certmanager_aws_access_key_id }} | ||
secretAccessKeySecretRef: | ||
name: aws-secret-access-key | ||
key: secret-access-key | ||
- complianceType: musthave | ||
objectDefinition: | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
name: ingress-cert | ||
namespace: openshift-ingress | ||
spec: | ||
secretName: ingress-cert | ||
duration: 2160h | ||
renewBefore: 360h | ||
usages: | ||
- server auth | ||
- client auth | ||
dnsNames: | ||
- "*.apps.{{ ocp4_workload_deploy_hosted_cluster_name }}.{{ ocp4_workload_deploy_hosted_cluster_base_domain }}" | ||
issuerRef: | ||
kind: ClusterIssuer | ||
name: letsencrypt-production-route53 | ||
group: cert-manager.io | ||
- complianceType: musthave | ||
objectDefinition: | ||
apiVersion: operator.openshift.io/v1 | ||
kind: IngressController | ||
metadata: | ||
name: default | ||
namespace: openshift-ingress-operator | ||
spec: | ||
defaultCertificate: | ||
name: ingress-cert |
Oops, something went wrong.