ansible-collections / ansible-collections/google.cloud

GCP authentication : allow the usage of token instead of Json key and allow SA impersonation

Open
#465 1 comment 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
Python
Stars
105
Forks
144
Avg merge
5d 10h
Merged PRs (30d)
4

Description

##### SUMMARY
We do not want to manage GCP json key of service account as it is a security issue, one have to renew them.
So, to achieve this, we use Hashicorp Vault to provide a Token (validity 1 hour).
##### ISSUE TYPE
- Feature Idea

##### COMPONENT NAME

##### ADDITIONAL INFORMATION
To authenticate ansible on GCP, we would like 2 new authentication ways :
- Provide a token instead of a json key
- Provide a token and a service account email to impersonate

In our use case, Vault gives a token of a SA which is only allowed to impersonate another SA which has the necessary roles to update the instances metadatas to setup a ssh key for Ansible

Thank you
MLD
```
- name: Create IP address with token but without impersonation
hosts: localhost
gather_facts: no

vars:
service_account_token: satoken
project: my-project
auth_kind: service-account-token
scopes:
- https://www.googleapis.com/auth/compute

tasks:

- name: Allocate an IP Address - with token only
gcp_compute_address:
state: present
name: 'test-address1'
region: 'us-west1'
project: "{{ project }}"
auth_kind: "{{ auth_kind }}"
service_account_token: "{{ service_account_token }}"
scopes: "{{ scopes }}"

- name: Create IP address with token and with impersonation
hosts: localhost
gather_facts: no

vars:
service_account_token: satoken
project: my-project
auth_kind: service-account-token-with-impersonation
service_account_email_to_impersonate:service_account_email
scopes:
- https://www.googleapis.com/auth/compute

tasks:

- name: Allocate an IP Address
gcp_compute_address:
state: present
name: 'test-address1'
region: 'us-west1'
project: "{{ project }}"
auth_kind: "{{ auth_kind }}"
service_account_token: "{{ service_account_token }}"
service_acount_to_impersonate:"{{service_acount_email_to_impersonate}}"
scopes: "{{ scopes }}"

```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how gcp_compute_address currently handles auth_kind and service-account credentials, then inspect the collection's existing GCP authentication implementation. Implement and verify token-only authentication and token-based service-account impersonation using the two configurations shown in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
google-cloud, python
Domain
authentication, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.