This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
490 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
.DS_Store |
This file contains 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 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,8 @@ | ||
# Machine responsible for generating GPG key (Only First machine will be used) | ||
[gpg] | ||
|
||
Dedicated OpenShift nodes for signing images | ||
[image_signers] | ||
|
||
All OpenShift Nodes in the cluster | ||
[nodes] |
This file contains 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,16 @@ | ||
--- | ||
|
||
# Generate a GPG Key | ||
- hosts: gpg[0] | ||
roles: | ||
- { role: gpg-generate, when: (generate_gpg_key is not defined) or (generate_gpg_key is defined and generate_gpg_key) } | ||
|
||
- hosts: nodes:!image_signers | ||
roles: | ||
- node-config | ||
|
||
- hosts: masters[0] | ||
roles: | ||
- ocp-setup | ||
|
||
|
This file contains 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 @@ | ||
../roles/ |
This file contains 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,22 @@ | ||
gpg-generate | ||
============ | ||
|
||
Role to generate GPG Keys to sign and validate images | ||
|
||
_Note_: This role does enable the Extra Packages for Enterprise Linux (EPEL) repository on the machine used to generate GPG keys | ||
|
||
# Overview | ||
|
||
Generates GPG keychains and exports the public key. Transfers these assets to the control node. | ||
|
||
# Role Variables | ||
|
||
The following variables dictate the execution of the role: | ||
|
||
|Variable|Description|Default Value| | ||
|--------|-----------|-------------| | ||
|`gpg_key_gen_user_name`| GPG Username | `openshift` | | ||
|`gpg_key_gen_user_email` | GPG Email Address (Also used for identity) | `openshift@example.com` | | ||
| `gpg_key_gen_length` | GPG Key Length | `2048` | | ||
|`gpg_key_gen_passphrase_enable` | Whether to enable a passphrase on the key (Should remain false) | `false` | | ||
|`gpg_local_base_dir`|Location where to store GPG Keys fetched from remote host | `{{ playbook_dir }}/gpg_remote`| |
This file contains 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,23 @@ | ||
--- | ||
|
||
epel_repo_url: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm" | ||
epel_repo_gpg_key_url: "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }}" | ||
epel_repofile_path: "/etc/yum.repos.d/epel.repo" | ||
|
||
# Create a custom GPG Directory | ||
gpg_home: ~/.gnupg-openshift | ||
|
||
gpg_key_gen_user_name: openshift | ||
gpg_key_gen_user_email: openshift@example.com | ||
gpg_key_gen_type: 1 | ||
gpg_key_gen_length: 2048 | ||
gpg_key_gen_expire_date: 0 | ||
gpg_key_gen_passphrase: "{{ lookup('password', '/tmp/passwordfile') }}" | ||
gpg_key_gen_passphrase_enable: false | ||
gpg_key_gen_uid: "{{ gpg_key_gen_user_name }} <{{ gpg_key_gen_user_email }}>" | ||
gpg_key_gen_path: "{{ gpg_key_gen_uid | hash('md5') }}" | ||
|
||
# Directory to Fetch Generated Files Locally | ||
gpg_local_base_dir: "{{ playbook_dir }}/gpg_remote" | ||
gpg_core_files_dir: "{{ gpg_local_base_dir }}/gpg_config" | ||
gpg_publickey_dir: "{{ gpg_local_base_dir }}/public_key" |
This file contains 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,8 @@ | ||
# Options for GnuPG | ||
|
||
#keyserver hkp://keys.gnupg.net | ||
use-agent | ||
|
||
auto-key-locate cert pka ldap hkps://hkp://keys.gnupg.net | ||
keyserver hkp://keys.gnupg.net | ||
require-cross-certification |
This file contains 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,20 @@ | ||
--- | ||
|
||
- name: Check if EPEL repo is already configured. | ||
stat: path={{ epel_repofile_path }} | ||
register: epel_repofile_result | ||
|
||
- name: Install EPEL repo. | ||
become: true | ||
yum: | ||
name: "{{ epel_repo_url }}" | ||
state: present | ||
register: result | ||
when: not epel_repofile_result.stat.exists | ||
|
||
- name: Import EPEL GPG key. | ||
become: true | ||
rpm_key: | ||
key: "{{ epel_repo_gpg_key_url }}" | ||
state: present | ||
when: not epel_repofile_result.stat.exists |
This file contains 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,118 @@ | ||
--- | ||
|
||
- include: epel.yml | ||
|
||
- name: Install GPG Dependencies | ||
become: true | ||
yum: | ||
name: "{{ item }}" | ||
state: latest | ||
with_items: | ||
- gnupg2 | ||
- rng-tools | ||
- haveged | ||
- name: Enable haveged | ||
become: true | ||
service: | ||
name: haveged | ||
state: started | ||
- name: Create GPG Home Directory | ||
file: | ||
state: directory | ||
mode: 0700 | ||
dest: "{{ gpg_home }}/.gnupg" | ||
|
||
- name: Set gpg pinentry mode to loopback in config file. | ||
lineinfile: | ||
dest: "{{ gpg_home }}/.gnupg/gpg.conf" | ||
line: "{{ item.line }}" | ||
regexp: "{{ item.regexp }}" | ||
mode: 0600 | ||
create: yes | ||
with_items: | ||
- line: "use-agent" | ||
regexp: "^use-agent" | ||
- line: "pinentry-mode loopback" | ||
regexp: "^pinentry-mode" | ||
|
||
- name: Set gpg-agent config file to allow loopback pinentry. | ||
lineinfile: | ||
dest: "{{ gpg_home }}/.gnupg/gpg-agent.conf" | ||
line: "{{ item.line }}" | ||
regexp: "{{ item.regexp }}" | ||
mode: 0600 | ||
create: yes | ||
with_items: | ||
- line: "allow-loopback-pinentry" | ||
regexp: "^allow-loopback-pinentry" | ||
|
||
- name: Copy GPG Configuration File | ||
copy: | ||
src: gpg.conf | ||
dest: "{{ gpg_home }}/.gnupg/gpg.conf" | ||
mode: 0600 | ||
|
||
- name: Generate GPG Template | ||
template: | ||
src: gpg-generate.j2 | ||
dest: "{{ gpg_home }}/gen-key-script-openshift" | ||
mode: 0600 | ||
|
||
|
||
- name: Check existing secret key | ||
shell: "gpg2 --list-secret-keys | grep '{{ gpg_key_gen_uid }}'" | ||
environment: | ||
GNUPGHOME: "{{ gpg_home }}/.gnupg" | ||
changed_when: false | ||
ignore_errors: true | ||
register: gpgkeys | ||
|
||
- name: Generate gpg key | ||
command: "gpg2 --batch --gen-key {{ gpg_home }}/gen-key-script-openshift chdir={{ gpg_home }}" | ||
environment: | ||
GNUPGHOME: "{{ gpg_home }}/.gnupg" | ||
when: gpgkeys is defined and gpgkeys.stdout == "" | ||
register: genkey | ||
|
||
- name: Export Public Key | ||
command: "gpg2 --batch --yes --armor --export --output {{ gpg_home }}/{{ gpg_key_gen_user_email }} {{ gpg_key_gen_user_email }} chdir={{ gpg_home }}" | ||
environment: | ||
GNUPGHOME: "{{ gpg_home }}/.gnupg" | ||
|
||
- name: Delete local folder | ||
delegate_to: localhost | ||
file: | ||
state: absent | ||
path: "{{ gpg_local_base_dir }}" | ||
|
||
- name: Create Local Folders for GPG Content | ||
delegate_to: localhost | ||
file: | ||
state: directory | ||
path: "{{ item }}" | ||
with_items: | ||
- "{{ gpg_core_files_dir }}" | ||
- "{{ gpg_publickey_dir }}" | ||
|
||
- name: Fetch GPG Files | ||
fetch: | ||
src: "{{ item }}" | ||
dest: "{{ gpg_core_files_dir }}/" | ||
flat: true | ||
with_items: | ||
- "{{ gpg_home }}/.gnupg/pubring.gpg" | ||
- "{{ gpg_home }}/.gnupg/secring.gpg" | ||
- "{{ gpg_home }}/.gnupg/trustdb.gpg" | ||
|
||
- name: Fetch GPG Public Key | ||
fetch: | ||
src: "{{ item }}" | ||
dest: "{{ gpg_publickey_dir }}/" | ||
flat: true | ||
with_items: | ||
- "{{ gpg_home }}/{{ gpg_key_gen_user_email }}" | ||
|
||
- name: Delete GPG Directory | ||
file: | ||
state: absent | ||
path: "{{ gpg_home }}" |
This file contains 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,11 @@ | ||
%echo Generating a basic OpenPGP key | ||
Key-Type: 1 | ||
Key-Length: {{ gpg_key_gen_length }} | ||
Name-Real: {{ gpg_key_gen_user_name }} | ||
Name-Email: {{ gpg_key_gen_user_email }} | ||
Expire-Date: {{ gpg_key_gen_expire_date }} | ||
{% if gpg_key_gen_passphrase_enable is defined and gpg_key_gen_passphrase_enable %} | ||
Passphrase: {{ gpg_key_gen_passphrase }} | ||
{% endif %} | ||
%commit | ||
%echo done |
This file contains 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,13 @@ | ||
node-config | ||
============= | ||
|
||
Configures an OpenShift node to support image signatures. | ||
|
||
## Role Variables | ||
|
||
This role contains a number of variables that drive the specific execution. The following variables are key to the functionality of this role: | ||
|
||
|Variable|Description| | ||
|--------|-----------| | ||
|`local_gpg_publickey`| Location of the public key to configure in OpenShift | | ||
|`ocp_registry`| Location of the OpenShift registry | |
This file contains 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,7 @@ | ||
--- | ||
|
||
gpg_publickey_file: "openshift@example.com" | ||
local_gpg_publickey: "{{ playbook_dir }}/gpg_remote/public_key/{{ gpg_publickey_file }}" | ||
ocp_registry: docker-registry.default.svc:5000 | ||
containers_public_key_dir: /etc/pki/containers | ||
|
Oops, something went wrong.