Skip to content

Commit e2ca452

Browse files
feat: handle tokens via Bitwarden Vault (#658)
feat: handle tokens via Bitwarden Vault Fixes packit/private#41 TODO: Update or write new documentation in packit/packit.dev. Update the format of logins for the production in Bitwarden Fixes packit/private#41 Reviewed-by: Laura Barcziová
2 parents db8277d + 3772444 commit e2ca452

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

secrets/packit/prod/centpkg-sig.conf.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ git_excludes =
2929

3030
[centpkg-sig.distgit]
3131
apibaseurl = https://gitlab.com
32-
token = {{ vault.packit_service.authentication['gitlab.com'].token }}
32+
{% set gitlab_forge = git_forges | selectattr('name', 'equalto', 'gitlab.com') | first %}
33+
{% set gitlab_fields = gitlab_forge['fields'] | items2dict(key_name='name') %}
34+
token = {{ gitlab_fields['token:key'] }}

secrets/packit/prod/packit-service.yaml.j2

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ fas_user: packit
55
keytab_path: /secrets/fedora.keytab
66
validate_webhooks: true
77

8+
# {{ ansible_managed }}
9+
# Please adjust the values in the respective logins in the Bitwarden Vault
10+
authentication:
11+
{% for forge in git_forges %}
12+
{% set fields = forge['fields'] | items2dict(key_name='name') %}
13+
{{ forge['name'] }}:
14+
instance_url: {{ forge['login']['uris'][0].uri }}
15+
# Login: {{ forge['login']['username'] }}
16+
# Token name: {{ fields.get('token:name') }}
17+
# Scope: {{ fields.get('token:permissions') }}
18+
# Expiration: {{ fields.get('token:expiration') }}
19+
token: {{ fields.get('token:key') }}
20+
{% if 'type' in fields and 'github_app' in fields['type'] %}
21+
# GitHub App set up
22+
github_app_id: '{{ fields.get('app_id') }}'
23+
github_app_private_key_path: {{ fields.get('app_private_key_path') }}
24+
{% endif %}
25+
{% if 'token:type' in fields %}
26+
type: {{ fields.get('token:type') }}
27+
{% endif %}
28+
29+
{% endfor %}
30+
831
{{ vault.packit_service | to_nice_yaml }}
932

1033
testing_farm_api_url: https://api.testing-farm.io/v0.1/

secrets/packit/stg/centpkg-sig.conf.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ git_excludes =
2929

3030
[centpkg-sig.distgit]
3131
apibaseurl = https://gitlab.com
32-
token = {{ vault.packit_service.authentication['gitlab.com'].token }}
32+
{% set gitlab_forge = git_forges | selectattr('name', 'equalto', 'gitlab.com') | first %}
33+
{% set gitlab_fields = gitlab_forge['fields'] | items2dict(key_name='name') %}
34+
token = {{ gitlab_fields['token:key'] }}

secrets/packit/stg/packit-service.yaml.j2

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@ keytab_path: /secrets/fedora.keytab
66
comment_command_prefix: "/packit-stg"
77
validate_webhooks: true
88

9+
# {{ ansible_managed }}
10+
# Please adjust the values in the respective logins in the Bitwarden Vault
11+
authentication:
12+
{% for forge in git_forges %}
13+
{% set fields = forge['fields'] | items2dict(key_name='name') %}
14+
{{ forge['name'] }}:
15+
instance_url: {{ forge['login']['uris'][0].uri }}
16+
# Login: {{ forge['login']['username'] }}
17+
# Token name: {{ fields.get('token:name') }}
18+
# Scope: {{ fields.get('token:permissions') }}
19+
# Expiration: {{ fields.get('token:expiration') }}
20+
token: {{ fields.get('token:key') }}
21+
{% if 'type' in fields and 'github_app' in fields['type'] %}
22+
# GitHub App set up
23+
github_app_id: '{{ fields.get('app_id') }}'
24+
github_app_private_key_path: {{ fields.get('app_private_key_path') }}
25+
{% endif %}
26+
{% if 'token:type' in fields %}
27+
type: {{ fields.get('token:type') }}
28+
{% endif %}
29+
30+
{% endfor %}
31+
932
{{ vault.packit_service | to_nice_yaml }}
1033

1134
# temporarily unavailable, use production in the meanwhile

tasks/set-facts.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,13 @@
4747
- always
4848
ansible.builtin.set_fact:
4949
redis_hostname: "{{ kv_database }}"
50+
51+
- name: Set Bitwarden URI
52+
ansible.builtin.set_fact:
53+
bw_uri: "ansible://{{ service }}/{{ deployment }}"
54+
55+
- name: Fetch git forges
56+
tags:
57+
- always
58+
ansible.builtin.set_fact:
59+
git_forges: "{{ lookup('community.general.bitwarden', bw_uri + '/git', search='') }}"

0 commit comments

Comments
 (0)