Skip to content

Commit 764f895

Browse files
committed
broaden default Quay OAuth scopes and add idempotent re-sync
Adds user:admin and org:admin to the default scopes. oauth_setup.yaml now skips org/app creation when quay-oauth-credentials already exists and only regenerates the token when scopes drift. A quay-oauth-sync tag in 06-day2.yaml covers existing clusters.
1 parent 45ae157 commit 764f895

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

defaults/quay_operator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ quayOAuthApp:
2323
name: "default-application"
2424
organization: "default-org"
2525
redirect_uri: "http://localhost:8080/callback"
26-
scopes: "repo:read repo:write repo:admin repo:create user:read"
26+
scopes: "repo:read repo:write repo:admin repo:create user:read user:admin org:admin"

operators/quay-operator/oauth_setup.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,28 @@
99
# This file sets the following variables:
1010
# - quay_oauth_client_id
1111
# - quay_oauth_client_secret
12-
# - quay_oauth_token
12+
# - quay_oauth_token (only when a token is (re)generated)
13+
14+
- name: Read existing OAuth credentials Secret
15+
no_log: true
16+
kubernetes.core.k8s_info:
17+
api_version: v1
18+
kind: Secret
19+
name: quay-oauth-credentials
20+
namespace: quay-enterprise
21+
register: r_quay_oauth_secret_existing
22+
23+
- name: Determine whether OAuth application is already provisioned
24+
ansible.builtin.set_fact:
25+
quay_oauth_secret_exists: "{{ r_quay_oauth_secret_existing.resources | default([]) | length > 0 }}"
26+
27+
- name: Reuse credentials from existing Secret
28+
no_log: true
29+
when: quay_oauth_secret_exists
30+
ansible.builtin.set_fact:
31+
quay_oauth_client_id: "{{ r_quay_oauth_secret_existing.resources[0].data['client-id'] | b64decode }}"
32+
quay_oauth_client_secret: "{{ r_quay_oauth_secret_existing.resources[0].data['client-secret'] | b64decode }}"
33+
quay_oauth_current_scopes: "{{ r_quay_oauth_secret_existing.resources[0].data['scopes'] | default('') | b64decode }}"
1334

1435
- name: Create Quay organization for OAuth application
1536
no_log: true
@@ -33,6 +54,7 @@
3354
retries: 3
3455
delay: 5
3556
when:
57+
- not quay_oauth_secret_exists
3658
- quay_initial_token is defined
3759
- quay_initial_token | length > 0
3860
until:
@@ -61,6 +83,7 @@
6183
retries: 5
6284
delay: 10
6385
when:
86+
- not quay_oauth_secret_exists
6487
- quay_initial_token is defined
6588
- quay_initial_token | length > 0
6689
until:
@@ -81,6 +104,7 @@
81104
- r_quay_oauth_app.json.client_secret is defined
82105

83106
- name: Get current quay-app Deployment state before config update
107+
when: not quay_oauth_secret_exists
84108
kubernetes.core.k8s_info:
85109
api_version: apps/v1
86110
kind: Deployment
@@ -108,6 +132,7 @@
108132
retries: "{{ k8s_retries }}"
109133
delay: "{{ k8s_delay }}"
110134
when:
135+
- not quay_oauth_secret_exists
111136
- quay_oauth_client_id is defined
112137
- quay_oauth_client_id | length > 0
113138
until: r_quay_config_secret_oauth is success
@@ -160,6 +185,7 @@
160185
when:
161186
- quay_oauth_client_id is defined
162187
- quay_oauth_client_id | length > 0
188+
- not quay_oauth_secret_exists or (quay_oauth_current_scopes.split() | sort) != (quayOAuthApp.scopes.split() | sort)
163189
until:
164190
- r_quay_oauth_token is defined
165191
- r_quay_oauth_token.status in [302, 303]

playbooks/06-day2.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@
8383
loop_var: openshift_version
8484
tags: acm-policy-catalogsources
8585

86+
- name: Sync Quay OAuth credentials with desired scopes
87+
when: quayOAuthApp.enabled | default(true)
88+
ansible.builtin.include_tasks:
89+
file: ../operators/quay-operator/oauth_setup.yaml
90+
apply:
91+
tags: quay-oauth-sync
92+
environment:
93+
KUBECONFIG: "{{ workingDir }}/ocp-cluster/auth/kubeconfig"
94+
tags: quay-oauth-sync
95+
8696
- name: Management cluster upgrade
8797
ansible.builtin.include_tasks:
8898
file: tasks/mgmt_cluster_upgrade.yaml

0 commit comments

Comments
 (0)