-
Notifications
You must be signed in to change notification settings - Fork 3
Support Application Credentials in shiftstack-qa automation #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tusharjadhav3302
wants to merge
2
commits into
main
Choose a base branch
from
support_app_creds_OSPRH-6485
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
45 changes: 45 additions & 0 deletions
45
collection/stages/roles/day2ops/tasks/procedures/rotate_app_creds.yml
This file contains hidden or 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,45 @@ | ||
| --- | ||
| # Source: https://github.com/shiftstack/installer/blob/master/docs/user/openstack/README.md#openstack-credentials-update | ||
| - name: Restore user/password auth to ensure full permissions for app credential creation | ||
| ansible.builtin.include_role: | ||
| name: shiftstack.stages.prepare | ||
| tasks_from: clouds.yml | ||
|
|
||
| - name: Create application credentials and update clouds.yaml | ||
| ansible.builtin.include_role: | ||
| name: shiftstack.stages.prepare | ||
| tasks_from: app_creds.yml | ||
|
|
||
| - name: Rotate OpenShift Cloud Credentials | ||
| ansible.builtin.shell: | | ||
| set -o pipefail && \ | ||
| cat {{ clouds_yaml_file_path }} | sed 's/{{ user_cloud }}:/openstack:/' | \ | ||
| oc set data -n kube-system secret/openstack-credentials clouds.yaml=- | ||
| environment: | ||
| KUBECONFIG: "{{ kubeconfig }}" | ||
| changed_when: true | ||
|
|
||
| - name: Get OpenStack Credentials from OCP cluster | ||
| ansible.builtin.shell: | | ||
| set -o pipefail && \ | ||
| oc get secret -n kube-system openstack-credentials -o json | jq -r '.data."clouds.yaml"' | base64 -d | ||
| environment: | ||
| KUBECONFIG: "{{ kubeconfig }}" | ||
| register: ocp_creds_output | ||
| changed_when: false | ||
|
|
||
| - name: Parse OCP credentials | ||
| ansible.builtin.set_fact: | ||
| ocp_creds: "{{ ocp_creds_output.stdout | from_yaml }}" | ||
|
|
||
| - name: Verify credentials rotated to application credentials | ||
| ansible.builtin.assert: | ||
| that: | ||
| - ocp_creds.clouds.openstack.auth_type == 'v3applicationcredential' | ||
| fail_msg: "Credential rotation failed — auth_type is not v3applicationcredential" | ||
| success_msg: "Credential rotation verified — auth_type is v3applicationcredential" | ||
|
|
||
| - name: Wait until the Cluster Operators are healthy | ||
| ansible.builtin.include_role: | ||
| name: tools_cluster_checks | ||
| tasks_from: wait_until_cluster_operators_ready.yml |
This file contains hidden or 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 hidden or 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,76 @@ | ||
| --- | ||
| - name: Delete stale temporary Application Credential from interrupted previous run | ||
| ansible.builtin.shell: | | ||
| openstack application credential delete {{ app_credential_name }}-new | ||
| environment: | ||
| OS_CLOUD: "{{ user_cloud }}" | ||
| failed_when: false | ||
| changed_when: false | ||
|
|
||
| - name: Create new Application Credential | ||
| ansible.builtin.shell: | | ||
| openstack application credential create \ | ||
| --description "App Creds - All roles" \ | ||
| "{{ app_credential_name }}-new" -f yaml | ||
| environment: | ||
| OS_CLOUD: "{{ user_cloud }}" | ||
| register: app_cred_output | ||
| changed_when: true | ||
|
|
||
| - name: Parse Application Credential output | ||
| ansible.builtin.set_fact: | ||
| app_cred_info: "{{ app_cred_output.stdout | from_yaml }}" | ||
|
|
||
| - name: Read current clouds.yaml | ||
| ansible.builtin.slurp: | ||
| src: "{{ clouds_yaml_file_path }}" | ||
| register: clouds_yaml_file | ||
|
|
||
| - name: Set clouds.yaml fact | ||
| ansible.builtin.set_fact: | ||
| clouds_yaml_params: "{{ clouds_yaml_file.content | b64decode | from_yaml }}" | ||
|
|
||
| - name: Build updated cloud entry with application credentials | ||
| ansible.builtin.set_fact: | ||
| updated_cloud_entry: | ||
| auth: | ||
| auth_url: "{{ clouds_yaml_params.clouds[user_cloud].auth.auth_url }}" | ||
| application_credential_id: "{{ app_cred_info.id }}" | ||
| application_credential_secret: "{{ app_cred_info.secret }}" | ||
| auth_type: v3applicationcredential | ||
| identity_api_version: "{{ clouds_yaml_params.clouds[user_cloud].identity_api_version | default('3') }}" | ||
| region_name: "{{ clouds_yaml_params.clouds[user_cloud].region_name | default(omit) }}" | ||
|
|
||
| - name: Add cacert to updated cloud entry | ||
| ansible.builtin.set_fact: | ||
| updated_cloud_entry: "{{ updated_cloud_entry | combine({'cacert': clouds_yaml_params.clouds[user_cloud].cacert}, recursive=True) }}" | ||
| when: clouds_yaml_params.clouds[user_cloud].cacert is defined | ||
|
|
||
| - name: Update clouds.yaml with application credentials | ||
| ansible.builtin.set_fact: | ||
| clouds_yaml_params: "{{ {'clouds': (clouds_yaml_params.clouds | combine({user_cloud: updated_cloud_entry}))} }}" | ||
|
|
||
| - name: Write updated clouds.yaml | ||
| ansible.builtin.copy: | ||
| content: "{{ clouds_yaml_params | to_nice_yaml(indent=4) }}" | ||
| dest: "{{ clouds_yaml_file_path }}" | ||
| mode: u=rw,g=rw,o=r | ||
|
|
||
| - name: Update clouds.yaml copy in osp_config_dir | ||
| ansible.builtin.copy: | ||
| content: "{{ clouds_yaml_params | to_nice_yaml(indent=4) }}" | ||
| dest: "{{ osp_config_dir }}/clouds.yaml" | ||
| mode: u=rw,g=rw,o=r | ||
| when: osp_config_dir is defined | ||
|
|
||
| - name: Validate new application credentials work | ||
| openstack.cloud.auth: | ||
| cloud: "{{ user_cloud }}" | ||
|
|
||
| - name: Delete previous Application Credential | ||
| ansible.builtin.shell: | | ||
| openstack application credential delete {{ app_credential_name }} | ||
| environment: | ||
| OS_CLOUD: "{{ user_cloud }}" | ||
| failed_when: false | ||
| changed_when: false |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
day2opsstage is added butuse_application_credentialsisn't set (defaults tofalse). This means the cluster installs with user/password, thenrotate_app_credsswitches it to app creds as a day2 operation.Is this the intended test flow? The Jenkins cp-migration multijob passes
OPENSHIFT_OPENSTACK_APP_CREDS=Truewhich enables BOTH prepare-time app creds AND day2ops rotation. If you want to test the prepare path too, adduse_application_credentials: truehere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, intentional for this PR — the test flow is: install with user/password, then
rotate_app_credsswitches to app creds as a day2 operation. This validates the rotation path. Enablinguse_application_credentials: truefor prepare-time testing can be added as a follow-up once the rotation path is proven in CI.