-
Notifications
You must be signed in to change notification settings - Fork 26
feat: Add argument spec validation to Certificate role #359
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
DonatSzabo
wants to merge
16
commits into
linux-system-roles:main
Choose a base branch
from
DonatSzabo:argument_specs_implementation-dszabo
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.
+675
−0
Open
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9e2056b
Implemented argument specs for certificate role
DonatSzabo de20a38
Small README change
DonatSzabo 19db6bd
Added test for the new argument spec implementation
DonatSzabo b5469ae
Added one more test for the trust entry
DonatSzabo 7db3de7
Added missed argument and reworked the test file
DonatSzabo dfcfe5c
Made recommended changes. Added assert_role_vars, refractored tests_i…
DonatSzabo 5d39654
Added test case to confirm that ansible iteras trough list arguments
DonatSzabo 4ddb0be
Good catch from coderabbit. Added stricter validation and a test for it
DonatSzabo e121f9b
A test to see if the argument specs file is triggering the failing ci…
DonatSzabo a09989a
Address CodeRabbit review: verify error messages in rescue blocks and…
DonatSzabo 8512131
Restore argument_specs.yml from testing rename
DonatSzabo fd1f6a6
Bug fix for CentOS 7
DonatSzabo 412af4f
Fixed small inconsistency
DonatSzabo 1138368
Bugfix for CentOS 7
DonatSzabo 57d72a7
Argument spec defaults moved from description to default:
DonatSzabo 709e85b
Changed tests mninimum version number from 2.10 to 2.11
DonatSzabo 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
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,182 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| argument_specs: | ||
| main: | ||
| short_description: The certificate role. | ||
| description: > | ||
| The certificate role allows you to issue and manage TLS/SSL | ||
| certificates using various CA providers such as self-sign and IPA. | ||
|
|
||
| This role will install necessary packages, configure the certificate | ||
| provider, and issue or renew certificates as specified in | ||
| `certificate_requests`. It can also manage system trust store | ||
| entries via `certificate_trust`. | ||
| options: | ||
| certificate_requests: | ||
| type: list | ||
| elements: dict | ||
| description: > | ||
| A list of certificate request specifications. Each item describes | ||
| a certificate to be issued or renewed. Defaults to an empty list. | ||
| options: | ||
| name: | ||
| type: str | ||
| required: true | ||
| description: > | ||
| The name of the certificate. A full path can be used to | ||
| choose the directory where files will be stored. | ||
| ca: | ||
| type: str | ||
| required: true | ||
| description: > | ||
| The CA that will issue the certificate (e.g. self-sign, ipa). | ||
| dns: | ||
| type: raw | ||
| description: > | ||
| A domain name or list of domain names to include in the | ||
| certificate Subject Alternative Name (SAN). | ||
| email: | ||
| type: raw | ||
| description: > | ||
| An email address or list of email addresses to include in the | ||
| certificate Subject Alternative Name (SAN). | ||
| ip: | ||
| type: raw | ||
| description: > | ||
| An IP address or list of IP addresses to include in the | ||
| certificate Subject Alternative Name (SAN). | ||
| auto_renew: | ||
| type: bool | ||
| description: > | ||
| Whether the certificate should be renewed automatically | ||
| before it expires. Defaults to `true`. | ||
| owner: | ||
| type: str | ||
| description: > | ||
| The user name or user id for the certificate and key files. | ||
| group: | ||
| type: str | ||
| description: > | ||
| The group name or group id for the certificate and key files. | ||
| mode: | ||
| type: raw | ||
| description: > | ||
| The file system permissions for the certificate and key | ||
| files. Accepts a string (e.g. '0644') or an integer. | ||
| key_size: | ||
| type: int | ||
| description: > | ||
| The key size in bits. | ||
| common_name: | ||
| type: str | ||
| description: > | ||
| The Common Name requested for the certificate subject. | ||
| country: | ||
| type: str | ||
| description: > | ||
| The country code requested for the certificate subject. | ||
| state: | ||
| type: str | ||
| description: > | ||
| The state requested for the certificate subject. | ||
| locality: | ||
| type: str | ||
| description: > | ||
| The locality requested for the certificate subject. | ||
| organization: | ||
| type: str | ||
| description: > | ||
| The organization requested for the certificate subject. | ||
| organizational_unit: | ||
| type: str | ||
| description: > | ||
| The organizational unit requested for the certificate subject. | ||
| contact_email: | ||
| type: str | ||
| description: > | ||
| The contact email requested for the certificate subject. | ||
| key_usage: | ||
| type: list | ||
| elements: str | ||
|
richm marked this conversation as resolved.
|
||
| choices: | ||
| - digitalSignature | ||
| - nonRepudiation | ||
| - keyEncipherment | ||
| - dataEncipherment | ||
| - keyAgreement | ||
| - keyCertSign | ||
| - cRLSign | ||
| - encipherOnly | ||
| - decipherOnly | ||
| description: > | ||
| The allowed Key Usage extensions for the certificate. | ||
| Defaults to `digitalSignature` and `keyEncipherment`. | ||
| extended_key_usage: | ||
| type: list | ||
| elements: str | ||
| description: > | ||
| The Extended Key Usage attributes for the certificate. | ||
| Defaults to `id-kp-serverAuth` and `id-kp-clientAuth`. | ||
| run_before: | ||
| type: str | ||
| description: > | ||
| A command to run before saving the certificate. | ||
| run_after: | ||
| type: str | ||
| description: > | ||
| A command to run after saving the certificate. | ||
| principal: | ||
| type: raw | ||
| description: > | ||
| A Kerberos principal or list of Kerberos principals. | ||
| provider: | ||
| type: str | ||
| description: > | ||
| The underlying method used to request and manage the | ||
| certificate. Defaults to `certmonger`. | ||
| issuer: | ||
| type: str | ||
| description: > | ||
| The issuer certificate nickname or template name. | ||
| certificate_wait: | ||
| type: bool | ||
| description: > | ||
| Whether the task should wait for the certificate to be issued. | ||
| Defaults to `true`. | ||
| certificate_trust: | ||
| type: list | ||
| elements: dict | ||
| description: > | ||
| A list of certificates to install into or remove from the system | ||
| trust store. Defaults to an empty list. | ||
| options: | ||
| name: | ||
| type: str | ||
| required: true | ||
| description: > | ||
| The base file name of the trust anchor. | ||
| content: | ||
| type: str | ||
| description: > | ||
| The inline PEM content of the certificate. | ||
| src: | ||
| type: str | ||
| description: > | ||
| The path of a certificate file to copy to the trust store. | ||
| remote_src: | ||
| type: bool | ||
| description: > | ||
| If true, `src` is a path on the managed host rather than | ||
| the controller. | ||
| url: | ||
| type: str | ||
| description: > | ||
| The URL to download the certificate from. | ||
| state: | ||
| type: str | ||
| choices: | ||
| - present | ||
| - absent | ||
| description: > | ||
| Whether the trust anchor should be present or absent. | ||
| Defaults to `present`. | ||
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,78 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| --- | ||
| - name: Assert dns is a string or list of strings | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| item.dns is string | ||
| or (item.dns is sequence and item.dns is not mapping | ||
| and item.dns | reject('string') | list | length == 0) | ||
| fail_msg: >- | ||
| certificate_requests[{{ idx }}].dns must be a string or list of | ||
| strings, got {{ item.dns | type_debug }} | ||
| loop: "{{ certificate_requests }}" | ||
| loop_control: | ||
| index_var: idx | ||
| label: "{{ item.name | d('unnamed') }}" | ||
| when: item.dns is defined | ||
|
|
||
| - name: Assert email is a string or list of strings | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| item.email is string | ||
| or (item.email is sequence and item.email is not mapping | ||
| and item.email | reject('string') | list | length == 0) | ||
| fail_msg: >- | ||
| certificate_requests[{{ idx }}].email must be a string or list of | ||
| strings, got {{ item.email | type_debug }} | ||
| loop: "{{ certificate_requests }}" | ||
| loop_control: | ||
| index_var: idx | ||
| label: "{{ item.name | d('unnamed') }}" | ||
| when: item.email is defined | ||
|
|
||
| - name: Assert ip is a string or list of strings | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| item.ip is string | ||
| or (item.ip is sequence and item.ip is not mapping | ||
| and item.ip | reject('string') | list | length == 0) | ||
| fail_msg: >- | ||
| certificate_requests[{{ idx }}].ip must be a string or list of | ||
| strings, got {{ item.ip | type_debug }} | ||
| loop: "{{ certificate_requests }}" | ||
| loop_control: | ||
| index_var: idx | ||
| label: "{{ item.name | d('unnamed') }}" | ||
| when: item.ip is defined | ||
|
|
||
| - name: Assert principal is a string or list of strings | ||
| ansible.builtin.assert: | ||
| that: | ||
| - >- | ||
| item.principal is string | ||
| or (item.principal is sequence and item.principal is not mapping | ||
| and item.principal | reject('string') | list | length == 0) | ||
| fail_msg: >- | ||
| certificate_requests[{{ idx }}].principal must be a string or list of | ||
| strings, got {{ item.principal | type_debug }} | ||
| loop: "{{ certificate_requests }}" | ||
| loop_control: | ||
| index_var: idx | ||
| label: "{{ item.name | d('unnamed') }}" | ||
| when: item.principal is defined | ||
|
|
||
| - name: Assert mode is a string or integer | ||
| ansible.builtin.assert: | ||
| that: | ||
| - (item.mode | type_debug) in ['str', 'int', 'unicode'] | ||
| fail_msg: >- | ||
| certificate_requests[{{ idx }}].mode must be a string or integer, | ||
| got {{ item.mode | type_debug }} | ||
| loop: "{{ certificate_requests }}" | ||
| loop_control: | ||
| index_var: idx | ||
| label: "{{ item.name | d('unnamed') }}" | ||
| when: item.mode is defined |
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
Oops, something went wrong.
Oops, something went wrong.
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.
why are
dns,email, andipusing typeraw? Is it because they can benull?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.
Its because these fields can accept a string or a list of strings.