Skip to content

Add initial implementation of scr_keys role for SSH credential retrie… - #1202

Open
dhruvmicrosoft wants to merge 1 commit into
Azure:release/july-2026from
dhruvmicrosoft:smcr_keys
Open

Add initial implementation of scr_keys role for SSH credential retrie…#1202
dhruvmicrosoft wants to merge 1 commit into
Azure:release/july-2026from
dhruvmicrosoft:smcr_keys

Conversation

@dhruvmicrosoft

Copy link
Copy Markdown

This pull request introduces the initial SAP System Copy and Refresh (SCR) Ansible automation framework, focusing on secure SSH credential management using Azure Key Vault and Managed Identity (MSI). It adds comprehensive documentation and the first SCR role, scr_keys, which retrieves and manages SSH credentials for SAP hosts, ensuring no static secrets are left on disk. The implementation emphasizes composability, security, and clear operational procedures.

SCR Framework Introduction and Documentation:

  • Added a top-level overview in roles-scr/README.md describing the SCR framework’s design, role responsibilities, and authentication model, including a roadmap for future roles.
  • Documented the scr_keys role in detail, covering inputs, outputs, Key Vault secret naming conventions, security notes, and integration patterns in scr_keys/README.md.

New Role: scr_keys Implementation:

  • Implemented scr_keys to securely fetch SSH usernames and private keys from Azure Key Vault via MSI, expose them as per-host Ansible facts, and remove temporary key files after use. [1] [2]
  • The credential retrieval and cleanup logic is delegated to the controller (localhost) to ensure secrets never reside on remote hosts and are properly shredded post-playbook. [1] [2]

Security and Operational Practices:

  • All sensitive operations are wrapped in no_log: true blocks, and key files are written with restrictive permissions (0600). The role does not set SSH options, leaving that to inventory or playbook configuration. [1] [2]
  • Tagging (silent_v1, silent_v2, secrets, cleanup) is used to control output verbosity and facilitate selective task execution. [1] [2]

Known Limitations and Future Work:

  • The documentation and inline TODOs highlight areas for improvement, such as refactoring variable construction, enhancing error handling, and switching to a native Ansible Azure module for identity discovery.

This PR lays the foundation for secure, modular SAP system automation on Azure, with clear documentation and a robust credential management workflow.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces the initial SCR Ansible framework and an scr_keys role for retrieving SSH credentials from Azure Key Vault using managed identity.

Changes:

  • Adds SCR framework and role documentation.
  • Implements workload-, SID-, and host-level credential retrieval.
  • Adds temporary key-file creation and cleanup behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
roles-scr/README.md Documents the SCR framework and roadmap.
scr_keys/README.md Documents role usage, security, and operations.
vars/main.yaml Defines secret names and cleanup defaults.
tasks/main.yaml Dispatches retrieval or cleanup tasks.
tasks/get_secrets.yaml Retrieves credentials and creates key files.
tasks/cleanup.yaml Removes temporary key files.

---
- name: "SCR Keys - Retrieve SSH credentials from Key Vault"
ansible.builtin.include_tasks:
file: roles-scr/scr_keys/tasks/get_secrets.yaml

- name: "SCR Keys - Remove temporary SSH key files"
ansible.builtin.include_tasks:
file: roles-scr/scr_keys/tasks/cleanup.yaml
Comment on lines +20 to +21
ansible.builtin.command: >-
az account show
ansible_ssh_common_args: {{ ansible_ssh_common_args | default('-') }}
_scr_username_{{ granularity }}: {{ lookup('vars', '_scr_username_' + granularity) }}
_scr_sshkey_{{ granularity }}: {{ lookup('vars', '_scr_sshkey_' + granularity) }}
verbosity: 1
- name: "SCR Keys: ({{ function | upper }}) Put private key into a temp file on controller (0600) (controller only)"
ansible.builtin.copy:
content: "{{ _results.secrets[0].secret }}"
dest: "/tmp/ansible_kv_key_{{ inventory_hostname }}"
# SSH access to the source and destination SAP systems for key management operations.
# - By removing these files at the end of the playbook, we enhance the security posture of the deployment process.
# ---------------------------------------------------------------------------*/
- name: "SCR Keys: ({{ function | upper }}) Cleanup the SSH credential files from the OS (controller only)"
- name: "SCR Keys: ({{ function | upper }}) Cleanup the SSH credential files from the OS (controller only)"
delegate_to: localhost
ansible.builtin.file:
path: "{{ ansible_ssh_private_key_file }}"
Comment on lines +196 to +197
Skip the identity chatter with `--skip-tags silent_v1`, or hide the
Key-Vault fetch traces with `--skip-tags silent_v2`. The recap `debug:`
Comment on lines +209 to +210
A calling playbook is expected to include the role three times — once
per side in `pre_tasks`, then once with `cleanup: true` in `post_tasks`:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants