Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_pki.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2025 Dell EMC
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for sonic_pki
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_pki
17 version_added: 2.3.0
18 short_description: 'Manages PKI attributes of Enterprise Sonic'
19 description: 'Manages PKI attributes of Enterprise Sonic'
20 author: Eric Seifert (@seiferteric)
21 notes:
22 - 'Tested against Dell Enterprise SONiC 4.1.0'
23 options:
24 config:
25 description: The provided configuration
26 type: dict
27 suboptions:
28 trust_stores:
29 description: Store of CA Certificates
30 type: list
31 elements: dict
32 suboptions:
33 name:
34 type: str
35 required: True
36 description: The name of the Trust Store
37 ca_name:
38 type: list
39 elements: str
40 description: List of CA certificates in the trust store.
41 security_profiles:
42 description: Application Security Profiles
43 type: list
44 elements: dict
45 suboptions:
46 profile_name:
47 type: str
48 required: True
49 description: Profile Name
50 certificate_name:
51 type: str
52 description: Host Certificate Name
53 trust_store:
54 type: str
55 description: Name of associated trust_store
56 revocation_check:
57 description: Require certificate revocation check succeeds
58 type: bool
59 peer_name_check:
60 description: Require peer name is verified
61 type: bool
62 key_usage_check:
63 description: Require key usage is enforced
64 type: bool
65 cdp_list:
66 description: Global list of CDP's
67 type: list
68 elements: str
69 ocsp_responder_list:
70 description: Global list of OCSP responders
71 type: list
72 elements: str
73 state:
74 description:
75 - The state of the configuration after module completion.
76 type: str
77 choices: ['merged', 'deleted', 'replaced', 'overridden']
78 default: merged
79 """
80
81 EXAMPLES = """
82 # Using "merged" state for initial config
83 #
84 # Before state:
85 # -------------
86 #
87 # sonic# show running-configuration | grep crypto
88 # sonic#
89 #
90 - name: "Initial Config"
91 dellemc.enterprise_sonic.sonic_pki:
92 config:
93 security_profiles:
94 - profile_name: rest
95 ocsp_responder_list:
96 - http://example.com/ocspa
97 - http://example.com/ocspb
98 certificate_name: host
99 trust_store: default-ts
100 trust_stores:
101 - name: default-ts
102 ca_name:
103 - CA2
104 state: merged
105
106 # After state:
107 # ------------
108 #
109 # sonic# show running-configuration | grep crypto
110 # crypto trust_store default-ts ca-cert CA2
111 # crypto security-profile rest
112 # crypto security-profile trust_store rest default-ts
113 # crypto security-profile certificate rest host
114 # crypto security-profile ocsp-list rest http://example.com/ocspa,http://example.com/ocspb
115
116 # Using "deleted" state to remove configuration
117 #
118 # Before state:
119 # ------------
120 #
121 # sonic# show running-configuration | grep crypto
122 # crypto trust_store default-ts ca-cert CA2
123 # crypto security-profile rest
124 # crypto security-profile trust_store rest default-ts
125 # crypto security-profile certificate rest host
126 # crypto security-profile ocsp-list rest http://example.com/ocsp
127 #
128 - name: PKI Delete Test
129 hosts: datacenter
130 gather_facts: true
131 connection: httpapi
132 tasks:
133 - name: Remove trust_store from security-profile
134 dellemc.enterprise_sonic.sonic_pki:
135 config:
136 security_profiles:
137 - profile_name: rest
138 trust_store: default-ts
139 state: deleted
140 # After state:
141 # ------------
142 #
143 # sonic# show running-configuration | grep crypto
144 # crypto trust_store default-ts ca-cert CA2
145 # crypto security-profile rest
146 # crypto security-profile certificate rest host
147 # crypto security-profile ocsp-list rest http://example.com/ocsp
148
149 # Using "overridden" state
150
151 # Before state:
152 # ------------
153 #
154 # sonic# show running-configuration | grep crypto
155 # crypto trust_store default-ts ca-cert CA2
156 # crypto security-profile rest
157 # crypto security-profile trust_store rest default-ts
158 # crypto security-profile certificate rest host
159 # crypto security-profile ocsp-list rest http://example.com/ocspa,http://example.com/ocspb
160 #
161 - name: "Overridden Config"
162 dellemc.enterprise_sonic.sonic_pki:
163 config:
164 security_profiles:
165 - profile_name: telemetry
166 ocsp_responder_list:
167 - http://example.com/ocspb
168 revocation_check: true
169 trust_store: telemetry-ts
170 certificate_name: host
171 trust_stores:
172 - name: telemetry-ts
173 ca_name: CA
174 state: overridden
175 # After state:
176 # -----------
177 #
178 # sonic# show running-configuration | grep crypto
179 # crypto trust_store telemetry-ts ca-cert CA
180 # crypto security-profile telemetry revocation_check true
181 # crypto security-profile trust_store telemetry telemetry-ts
182 # crypto security-profile certificate telemetry host
183 # crypto security-profile ocsp-list telemetry http://example.com/ocspb
184
185 # Using "replaced" state to update config
186
187 # Before state:
188 # ------------
189 #
190 # sonic# show running-configuration | grep crypto
191 # crypto trust_store default-ts ca-cert CA2
192 # crypto security-profile rest
193 # crypto security-profile trust_store rest default-ts
194 # crypto security-profile certificate rest host
195 # crypto security-profile ocsp-list rest http://example.com/ocspa,http://example.com/ocspb
196 #
197 - name: "Replace Config"
198 dellemc.enterprise_sonic.sonic_pki:
199 config:
200 security_profiles:
201 - profile_name: rest
202 ocsp_responder_list:
203 - http://example.com/ocsp
204 revocation_check: false
205 trust_store: default-ts
206 certificate_name: host
207 state: replaced
208 # After state:
209 # -----------
210 #
211 # sonic# show running-configuration | grep crypto
212 # crypto trust_store default-ts ca-cert CA2
213 # crypto security-profile rest
214 # crypto security-profile trust_store rest default-ts
215 # crypto security-profile certificate rest host
216 # crypto security-profile ocsp-list rest http://example.com/ocsp
217 """
218
219 RETURN = """
220 before:
221 description: The configuration prior to the module invocation.
222 returned: always
223 type: dict
224 sample: >
225 The configuration returned will always be in the same format
226 as the parameters above.
227 after:
228 description: The resulting configuration module invocation.
229 returned: when changed
230 type: dict
231 sample: >
232 The configuration returned will always be in the same format
233 as the parameters above.
234 commands:
235 description: The set of commands pushed to the remote device.
236 returned: always
237 type: list
238 sample: ['command 1', 'command 2', 'command 3']
239 """
240
241
242 from ansible.module_utils.basic import AnsibleModule
243 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.pki.pki import PkiArgs
244 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.pki.pki import Pki
245
246
247 def main():
248 """
249 Main entry point for module execution
250
251 :returns: the result form module invocation
252 """
253 module = AnsibleModule(argument_spec=PkiArgs.argument_spec,
254 supports_check_mode=True)
255
256 result = Pki(module).execute_module()
257 module.exit_json(**result)
258
259
260 if __name__ == '__main__':
261 main()