Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_confidential_compute.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'community'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: intersight_confidential_compute
16 short_description: Confidential computing BIOS policy for Cisco Intersight
17 description:
18 - Creates BIOS policies with hardware-level confidential computing features enabled.
19 - Supports AMD SEV (Secure Encrypted Virtualization), AMD SEV-SNP, and Intel SGX
20 (Software Guard Extensions) for secure AI enclaves.
21 - Combines the correct BIOS knob settings needed to enable memory encryption and
22 trusted execution environments on Cisco UCS servers.
23 - Intended for AI workloads that require protection of proprietary model data in memory.
24 - For more information see L(Cisco Intersight,https://intersight.com/apidocs).
25 extends_documentation_fragment: intersight
26 options:
27 state:
28 description:
29 - If C(present), will verify the resource is present and will create if needed.
30 - If C(absent), will verify the resource is absent and will delete if needed.
31 type: str
32 choices: [present, absent]
33 default: present
34 organization:
35 description:
36 - The name of the Organization this resource is assigned to.
37 - Profiles and Policies that are created within a Custom Organization are applicable only to devices in the same Organization.
38 type: str
39 default: default
40 name:
41 description:
42 - The name assigned to the BIOS policy.
43 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
44 type: str
45 required: true
46 tags:
47 description:
48 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
49 type: list
50 elements: dict
51 description:
52 description:
53 - The user-defined description of the BIOS policy.
54 type: str
55 aliases: [descr]
56 security_profile:
57 description:
58 - The confidential computing security profile to apply.
59 - C(amd_sev) enables AMD Secure Encrypted Virtualization with memory encryption for VMs.
60 Encrypts VM memory with per-VM keys so the hypervisor cannot read guest data.
61 Requires AMD EPYC processors (Milan/Genoa or later).
62 - C(amd_sev_snp) enables AMD SEV with Secure Nested Paging for stronger isolation.
63 Adds integrity protection on top of SEV memory encryption, preventing hypervisor
64 tampering with guest memory mappings. Requires AMD EPYC Genoa or later.
65 - C(intel_sgx) enables Intel Software Guard Extensions for application-level enclaves.
66 Creates hardware-encrypted memory enclaves that protect specific application data
67 even from the OS and hypervisor. Requires Intel Xeon Scalable (Ice Lake or later).
68 - C(intel_sgx_with_auto_reg) enables Intel SGX with automatic registration agent.
69 Includes all intel_sgx settings plus enables the SGX auto-registration agent for
70 simplified attestation service enrollment.
71 type: str
72 choices: [amd_sev, amd_sev_snp, intel_sgx, intel_sgx_with_auto_reg]
73 required: true
74 sev_asid_count:
75 description:
76 - Number of AMD SEV Address Space Identifiers (ASIDs) to allocate.
77 - Higher ASID counts allow more concurrent encrypted VMs but may reduce available ASIDs for SEV-SNP.
78 - Only applicable for amd_sev and amd_sev_snp security profiles.
79 type: str
80 choices: [platform-default, '253 ASIDs', '509 ASIDs']
81 sgx_epoch0:
82 description:
83 - Intel SGX Epoch 0 value. Changing this invalidates all existing SGX sealed data.
84 - Only applicable for intel_sgx and intel_sgx_with_auto_reg profiles.
85 - Use with caution in production environments.
86 type: str
87 sgx_epoch1:
88 description:
89 - Intel SGX Epoch 1 value. Changing this invalidates all existing SGX sealed data.
90 - Only applicable for intel_sgx and intel_sgx_with_auto_reg profiles.
91 - Use with caution in production environments.
92 type: str
93 enable_tme:
94 description:
95 - Override for Intel Total Memory Encryption (TME).
96 - TME is a prerequisite for SGX and encrypts all system memory with a platform key.
97 - Automatically enabled by intel_sgx profiles; set explicitly only to override.
98 type: str
99 choices: [platform-default, enabled, disabled]
100 numa_optimized:
101 description:
102 - Override for NUMA optimization.
103 - All confidential compute profiles enable NUMA optimization by default.
104 type: str
105 choices: [platform-default, enabled, disabled]
106 author:
107 - Steve Fulmer (@stevefulme1)
108 '''
109
110 EXAMPLES = r'''
111 - name: Create AMD SEV policy for encrypted AI VMs
112 cisco.intersight.intersight_confidential_compute:
113 api_private_key: "{{ api_private_key }}"
114 api_key_id: "{{ api_key_id }}"
115 organization: AI-Factory
116 name: bios-amd-sev-ai
117 description: AMD SEV for secure AI inference VMs
118 security_profile: amd_sev
119 sev_asid_count: "509 ASIDs"
120
121 - name: Create AMD SEV-SNP policy for maximum VM isolation
122 cisco.intersight.intersight_confidential_compute:
123 api_private_key: "{{ api_private_key }}"
124 api_key_id: "{{ api_key_id }}"
125 name: bios-sev-snp-training
126 description: SEV-SNP for secure model training
127 security_profile: amd_sev_snp
128
129 - name: Create Intel SGX policy for enclave-based inference
130 cisco.intersight.intersight_confidential_compute:
131 api_private_key: "{{ api_private_key }}"
132 api_key_id: "{{ api_key_id }}"
133 name: bios-sgx-inference
134 description: SGX enclaves for confidential inference
135 security_profile: intel_sgx_with_auto_reg
136
137 - name: Delete confidential compute policy
138 cisco.intersight.intersight_confidential_compute:
139 api_private_key: "{{ api_private_key }}"
140 api_key_id: "{{ api_key_id }}"
141 name: bios-amd-sev-ai
142 security_profile: amd_sev
143 state: absent
144 '''
145
146 RETURN = r'''
147 api_response:
148 description: The API response output returned by the specified resource.
149 returned: always
150 type: dict
151 sample:
152 "api_response": {
153 "Name": "bios-amd-sev-ai",
154 "ObjectType": "bios.Policy",
155 "Sev": "509 ASIDs",
156 "CbsSevSnpSupport": "enabled"
157 }
158 applied_settings:
159 description: The BIOS settings applied by the security profile and any overrides.
160 returned: when state is present
161 type: dict
162 '''
163
164
165 from ansible.module_utils.basic import AnsibleModule
166 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
167
168
169 # Confidential computing security profile presets
170 SECURITY_PROFILES = {
171 'amd_sev': {
172 # AMD SEV - memory encryption for VMs
173 'Sev': '509 ASIDs',
174 # NUMA optimization for consistent memory locality
175 'NumaOptimized': 'enabled',
176 # IOMMU required for SEV
177 'CbsDfCmnDramNps': 'Auto',
178 # SMT enabled for VM density
179 'CpuHwpm': 'HWPM Native Mode',
180 },
181 'amd_sev_snp': {
182 # AMD SEV-SNP - memory encryption + integrity protection
183 'Sev': '509 ASIDs',
184 'CbsSevSnpSupport': 'enabled',
185 'NumaOptimized': 'enabled',
186 'CbsDfCmnDramNps': 'Auto',
187 'CpuHwpm': 'HWPM Native Mode',
188 },
189 'intel_sgx': {
190 # Intel SGX - application-level enclaves
191 'EnableSgx': 'enabled',
192 'EnableTme': 'enabled',
193 'NumaOptimized': 'enabled',
194 'CpuHwpm': 'HWPM Native Mode',
195 },
196 'intel_sgx_with_auto_reg': {
197 # Intel SGX with auto-registration for attestation
198 'EnableSgx': 'enabled',
199 'EnableTme': 'enabled',
200 'SgxAutoRegistrationAgent': 'enabled',
201 'NumaOptimized': 'enabled',
202 'CpuHwpm': 'HWPM Native Mode',
203 },
204 }
205
206 # Map of override parameter names to API property names
207 OVERRIDE_MAP = {
208 'enable_tme': 'EnableTme',
209 'numa_optimized': 'NumaOptimized',
210 }
211
212
213 def main():
214 argument_spec = intersight_argument_spec.copy()
215 argument_spec.update(
216 state=dict(type='str', choices=['present', 'absent'], default='present'),
217 organization=dict(type='str', default='default'),
218 name=dict(type='str', required=True),
219 description=dict(type='str', aliases=['descr']),
220 tags=dict(type='list', elements='dict'),
221 security_profile=dict(
222 type='str',
223 choices=['amd_sev', 'amd_sev_snp', 'intel_sgx', 'intel_sgx_with_auto_reg'],
224 required=True,
225 ),
226 sev_asid_count=dict(type='str', choices=['platform-default', '253 ASIDs', '509 ASIDs']),
227 sgx_epoch0=dict(type='str'),
228 sgx_epoch1=dict(type='str'),
229 enable_tme=dict(type='str', choices=['platform-default', 'enabled', 'disabled']),
230 numa_optimized=dict(type='str', choices=['platform-default', 'enabled', 'disabled']),
231 )
232
233 module = AnsibleModule(
234 argument_spec,
235 supports_check_mode=True,
236 )
237
238 intersight = IntersightModule(module)
239 intersight.result['api_response'] = {}
240 intersight.result['trace_id'] = ''
241
242 resource_path = '/bios/Policies'
243
244 intersight.api_body = {
245 'Name': intersight.module.params['name'],
246 'Organization': {
247 'Name': intersight.module.params['organization'],
248 },
249 }
250
251 if module.params['state'] == 'present':
252 intersight.set_tags_and_description()
253
254 # Apply security profile preset
255 profile_name = module.params['security_profile']
256 profile_settings = SECURITY_PROFILES[profile_name].copy()
257
258 # Apply SEV ASID count override for AMD profiles
259 if module.params.get('sev_asid_count') is not None and profile_name in ('amd_sev', 'amd_sev_snp'):
260 profile_settings['Sev'] = module.params['sev_asid_count']
261
262 # Apply SGX epoch overrides for Intel profiles
263 if profile_name in ('intel_sgx', 'intel_sgx_with_auto_reg'):
264 if module.params.get('sgx_epoch0') is not None:
265 profile_settings['SgxEpoch0'] = module.params['sgx_epoch0']
266 if module.params.get('sgx_epoch1') is not None:
267 profile_settings['SgxEpoch1'] = module.params['sgx_epoch1']
268
269 # Apply generic overrides
270 for param_name, api_property in OVERRIDE_MAP.items():
271 if module.params.get(param_name) is not None:
272 profile_settings[api_property] = module.params[param_name]
273
274 intersight.api_body.update(profile_settings)
275 intersight.result['applied_settings'] = profile_settings
276
277 intersight.configure_policy_or_profile(resource_path=resource_path)
278
279 module.exit_json(**intersight.result)
280
281
282 if __name__ == '__main__':
283 main()