-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup-sso.yml
More file actions
194 lines (192 loc) · 7.84 KB
/
Copy pathsetup-sso.yml
File metadata and controls
194 lines (192 loc) · 7.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
---
- hosts: masters[0]
vars_files:
- ssovars.yml
vars:
description: "SSO Setup"
create_data:
clientId: "openshift"
name: "OpenShift"
description: "OpenShift Console Authentication"
enabled: true
protocol: "openid-connect"
clientAuthenticatorType: "client-secret"
directAccessGrantsEnabled: true
redirectUris: ["https://{{api_master}}:8443/*"]
webOrigins: []
publicClient: false
consentRequired: false
frontchannelLogout: false
standardFlowEnabled: true
tasks:
- debug:
msg: "Domain: {{sso_domain}}"
- set_fact: idm_dir="/home/{{sso_username}}/{{sso_project}}"
- debug:
msg: "Idm dir {{ idm_dir }}"
- name: Install Java
yum:
name: java-1.8.0-openjdk
state: latest
- name: Cleanup old idm directory
file:
state: absent
path: "{{idm_dir}}"
- name: Create new idm directory
file:
state: directory
path: "{{idm_dir}}"
- name: Delete service account
command: oc delete service account "{{sso_project}}-service_account"
ignore_errors: yes
register: result
failed_when:
- "result.rc > 10"
- name: Delete Secret
command: oc delete secret "{{sso_project}}-app-secret"
ignore_errors: yes
register: result
failed_when:
- "result.rc > 10"
- name: Delete Old Project
command: oc delete project "{{sso_project}}"
ignore_errors: yes
register: result
failed_when:
- "result.rc > 10"
- name: Pause for cleanup of old install
pause:
minutes: 2
- set_fact: sso_projectid="{{sso_project}}"
- set_fact: idm_xpassword="Xp-{{sso_password}}"
- name: Create Openshift Project for SSO
command: oc new-project "{{sso_project}}"
- name: Create Service Account
command: "oc create serviceaccount {{sso_project}}-service-account"
- name: Add admin role to user
command: "oadm policy add-role-to-user admin {{sso_username}}"
- name: Add view to user
command: "oc policy add-role-to-user view system:serviceaccount:gsw1v36idm:{{sso_project}}-service-account"
- name: Stage 1 - OpenSSL Request
command: "openssl req -new -passout pass:{{idm_xpassword}} -newkey rsa:4096 -x509 -keyout {{idm_dir}}/xpaas.key -out {{idm_dir}}/xpaas.crt -days 365 -subj /CN=xpaas-sso.ca"
- name: Stage 2 - GENKEYPAIR
command: "keytool -genkeypair -deststorepass {{idm_xpassword}} -storepass {{idm_xpassword}} -keypass {{idm_xpassword}} -keyalg RSA -keysize 2048 -dname CN={{hostname_https}} -alias sso-https-key -keystore {{idm_dir}}/sso-https.jks"
- name: Stage 3 - CERTREQ
command: "keytool -deststorepass {{idm_xpassword}} -storepass {{idm_xpassword}} -keypass {{idm_xpassword}} -certreq -keyalg rsa -alias sso-https-key -keystore {{idm_dir}}/sso-https.jks -file {{idm_dir}}/sso.csr"
- name: Stage 4 - X509
command: "openssl x509 -req -passin pass:{{idm_xpassword}} -CA {{idm_dir}}/xpaas.crt -CAkey {{idm_dir}}/xpaas.key -in {{idm_dir}}/sso.csr -out {{idm_dir}}/sso.crt -days 365 -CAcreateserial"
- name: Stage 5 - IMPORT CRT
command: "keytool -noprompt -deststorepass {{idm_xpassword}} -import -file {{idm_dir}}/xpaas.crt -storepass {{idm_xpassword}} -keypass {{idm_xpassword}} -alias xpaas.ca -keystore {{idm_dir}}/sso-https.jks"
- name: Stage 6 - IMPORT SSO
command: "keytool -noprompt -deststorepass {{idm_xpassword}} -storepass {{idm_xpassword}} -keypass {{idm_xpassword}} -import -file {{idm_dir}}/sso.crt -alias sso-https-key -keystore {{idm_dir}}/sso-https.jks"
- name: Stage 7 - IMPORT XPAAS
command: "keytool -noprompt -deststorepass {{idm_xpassword}} -storepass {{idm_xpassword}} -keypass {{idm_xpassword}} -import -file {{idm_dir}}/xpaas.crt -alias xpaas.ca -keystore {{idm_dir}}/truststore.jks"
- name: Stage 8 - GENSECKEY
command: "keytool -deststorepass {{idm_xpassword}} -storepass {{idm_xpassword}} -keypass {{idm_xpassword}} -genseckey -alias jgroups -storetype JCEKS -keystore {{idm_dir}}/jgroups.jceks"
- name: Stage 9 - OCCREATE SECRET
command: "oc create secret generic sso-app-secret --from-file={{idm_dir}}/jgroups.jceks --from-file={{idm_dir}}/sso-https.jks --from-file={{idm_dir}}/truststore.jks"
- name: Stage 10 - OCCREATE SECRET ADD
command: "oc secret add sa/{{sso_project}}-service-account secret/sso-app-secret"
- name: Stage 11 - Create App Parameters
blockinfile:
path: "{{idm_dir}}/sso.params"
create: yes
block: |
HOSTNAME_HTTP="nlogin.{{sso_domain}}"
HOSTNAME_HTTPS="login.{{sso_domain}}"
APPLICATION_NAME="{{sso_project}}"
HTTPS_KEYSTORE="sso-https.jks"
HTTPS_PASSWORD="{{idm_xpassword}}"
HTTPS_SECRET="sso-app-secret"
JGROUPS_ENCRYPT_KEYSTORE="jgroups.jceks"
JGROUPS_ENCRYPT_PASSWORD="{{idm_xpassword}}"
JGROUPS_ENCRYPT_SECRET="sso-app-secret"
SERVICE_ACCOUNT_NAME={{sso_project}}-service-account
SSO_REALM=cloud
SSO_SERVICE_USERNAME="{{sso_username}}"
SSO_SERVICE_PASSWORD="{{sso_password}}"
SSO_ADMIN_USERNAME=admin
SSO_ADMIN_PASSWORD="adm-{{sso_password}}"
SSO_TRUSTSTORE=truststore.jks
SSO_TRUSTSTORE_PASSWORD="{{idm_xpassword}}"
- name: Stage 10 - OCCREATE SECRET ADD
command: oc new-app sso71-postgresql --param-file {{idm_dir}}/sso.params -l app=sso71-postgresql -l application=sso -l template=sso71-https
- set_fact: sso_token_url="https://login.{{sso_domain}}/auth/realms/cloud/protocol/openid-connect/token"
- name: Pause for app create
pause:
minutes: 4
- name: Login to SSO and Get Token
uri:
url: "{{sso_token_url}}"
method: POST
body: "grant_type=password&client_id=admin-cli&username={{sso_username}}&password={{sso_password}}"
return_content: yes
status_code: 200
validate_certs: no
register: login
until: login.status == 200
retries: 90
delay: 30
- debug: var=login.json.access_token
- name: Create SSO Client for Openshift
uri:
url: "https://login.{{sso_domain}}/auth/realms/cloud/clients-registrations/default"
method: POST
headers:
"Authorization": "bearer {{login.json.access_token}}"
"Content-Type": "application/json"
body: "{{ create_data | to_json }}"
return_content: yes
status_code: 201
validate_certs: no
register: create
- debug: var=create.json.secret
- hosts: masters
vars_files:
- ssovars.yml
tasks:
- name: Copy xpass.conf to masters
copy:
src: "{{idm_dir}}/xpaas.crt"
dest: /etc/origin/master/xpaas.crt
owner: root
mode: 0600
- name: Setup SSO Config
blockinfile:
backup: yes
dest: /etc/origin/master/master-config.yaml
insertafter: HTPasswdPasswordIdentityProvider
block: |1
- name: sso
challenge: false
login: true
mappingInfo: add
provider:
apiVersion: v1
kind: OpenIDIdentityProvider
clientID: openshift
clientSecret: {{create.json.secret}}
ca: xpaas.crt
urls:
authorize: https://login.{{sso_domain}}/auth/realms/cloud/protocol/openid-connect/auth
token: https://login.{{sso_domain}}/auth/realms/cloud/protocol/openid-connect/token
userInfo: https://login.{{sso_domain}}/auth/realms/cloud/protocol/openid-connect/userinfo
claims:
id:
- sub
preferredUsername:
- preferred_username
name:
- name
email:
- email
- service:
name: atomic-openshift-master
state: restarted
- name: Pause for service restart
pause:
seconds: 10
- name: Add our user as cluster admin
command: oc adm policy add-cluster-role-to-user cluster-admin "{{sso_username}}"
- debug:
msg: "Completed"