|
| 1 | +private import bicep |
| 2 | +private import codeql.bicep.Concepts |
| 3 | +private import Network |
| 4 | + |
| 5 | +module KeyVault { |
| 6 | + class VaultResource extends Resource { |
| 7 | + /** |
| 8 | + * Constructs a VaultResource for any Microsoft.KeyVault resource type. |
| 9 | + */ |
| 10 | + VaultResource() { this.getResourceType().regexpMatch("^Microsoft.KeyVault/.*") } |
| 11 | + |
| 12 | + string tenantId() { result = this.getProperties().getTenantId().getValue() } |
| 13 | + |
| 14 | + KeyVaultProperties::Properties getProperties() { result = this.getProperty("properties") } |
| 15 | + |
| 16 | + KeyVaultProperties::AccessPolicy getAccessPolicies() { |
| 17 | + result = this.getProperties().getAccessPolicies() |
| 18 | + } |
| 19 | + |
| 20 | + Network::NetworkAcl getNetworkAcls() { |
| 21 | + result = this.getProperties().getNetworkAcls() |
| 22 | + } |
| 23 | + |
| 24 | + override string toString() { result = "Key Vault Resource" } |
| 25 | + } |
| 26 | + |
| 27 | + class PublicVaultResource extends PublicResource { |
| 28 | + private VaultResource vaultResource; |
| 29 | + |
| 30 | + /** |
| 31 | + * Constructs a PublicVaultResource for any Microsoft.KeyVault resource type |
| 32 | + * that has public network access enabled. |
| 33 | + */ |
| 34 | + PublicVaultResource() { |
| 35 | + vaultResource.getProperties().publicNetworkAccess() = "Enabled" and |
| 36 | + this = vaultResource |
| 37 | + } |
| 38 | + |
| 39 | + override Expr getPublicAccessProperty() { |
| 40 | + result = vaultResource.getProperties().getPublicNetworkAccess() |
| 41 | + } |
| 42 | + |
| 43 | + override string toString() { result = "Public Key Vault Resource" } |
| 44 | + } |
| 45 | + |
| 46 | + module KeyVaultProperties { |
| 47 | + /** |
| 48 | + * The properties object for the Microsoft.KeyVault/vaults type. |
| 49 | + */ |
| 50 | + class Properties extends Object { |
| 51 | + private VaultResource vaultResource; |
| 52 | + |
| 53 | + /** |
| 54 | + * Constructs a Properties object for the given Key Vault resource. |
| 55 | + */ |
| 56 | + Properties() { this = vaultResource.getProperty("properties") } |
| 57 | + |
| 58 | + /** |
| 59 | + * Returns the parent VaultResource. |
| 60 | + */ |
| 61 | + VaultResource getVaultResource() { result = vaultResource } |
| 62 | + |
| 63 | + StringLiteral getTenantId() { result = this.getProperty("tenantId") } |
| 64 | + |
| 65 | + string tenantId() { result = this.getTenantId().getValue() } |
| 66 | + |
| 67 | + StringLiteral getCreateMode() { result = this.getProperty("createMode") } |
| 68 | + |
| 69 | + string createMode() { result = this.getCreateMode().getValue() } |
| 70 | + |
| 71 | + Boolean getEnabledForDeployment() { result = this.getProperty("enabledForDeployment") } |
| 72 | + |
| 73 | + boolean enabledForDeployment() { result = this.getEnabledForDeployment().getBool() } |
| 74 | + |
| 75 | + Boolean getEnabledForDiskEncryption() { |
| 76 | + result = this.getProperty("enabledForDiskEncryption") |
| 77 | + } |
| 78 | + |
| 79 | + boolean enabledForDiskEncryption() { result = this.getEnabledForDiskEncryption().getBool() } |
| 80 | + |
| 81 | + Boolean getEnabledForTemplateDeployment() { |
| 82 | + result = this.getProperty("enabledForTemplateDeployment") |
| 83 | + } |
| 84 | + |
| 85 | + boolean enabledForTemplateDeployment() { |
| 86 | + result = this.getEnabledForTemplateDeployment().getBool() |
| 87 | + } |
| 88 | + |
| 89 | + Boolean getSoftDeleteEnabled() { result = this.getProperty("softDeleteEnabled") } |
| 90 | + |
| 91 | + boolean softDeleteEnabled() { result = this.getSoftDeleteEnabled().getBool() } |
| 92 | + |
| 93 | + Boolean getPurgeProtectionEnabled() { result = this.getProperty("purgeProtectionEnabled") } |
| 94 | + |
| 95 | + boolean purgeProtectionEnabled() { result = this.getPurgeProtectionEnabled().getBool() } |
| 96 | + |
| 97 | + StringLiteral getPublicNetworkAccess() { result = this.getProperty("publicNetworkAccess") } |
| 98 | + |
| 99 | + string publicNetworkAccess() { result = this.getPublicNetworkAccess().getValue() } |
| 100 | + |
| 101 | + Network::NetworkAcl getNetworkAcls() { |
| 102 | + result = this.getProperty("networkAcls") |
| 103 | + } |
| 104 | + |
| 105 | + AccessPolicy getAccessPolicies() { |
| 106 | + result = this.getProperty("accessPolicies").(Array).getElements() |
| 107 | + } |
| 108 | + |
| 109 | + AccessPolicy getAccessPolicy(int index) { |
| 110 | + result = this.getProperty("accessPolicies").(Array).getElement(index) |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + class AccessPolicy extends Object { |
| 115 | + private KeyVaultProperties::Properties properties; |
| 116 | + |
| 117 | + /** |
| 118 | + * Constructs an AccessPolicy object for the given Key Vault properties. |
| 119 | + */ |
| 120 | + AccessPolicy() { this = properties.getProperty("accessPolicies").(Array).getElements() } |
| 121 | + |
| 122 | + /** |
| 123 | + * Returns the tenant ID of the access policy. |
| 124 | + */ |
| 125 | + string getTenantId() { result = this.getProperty("tenantId").(StringLiteral).getValue() } |
| 126 | + |
| 127 | + /** |
| 128 | + * Returns the object ID of the access policy. |
| 129 | + */ |
| 130 | + string getObjectId() { result = this.getProperty("objectId").(StringLiteral).getValue() } |
| 131 | + |
| 132 | + string toString() { result = "AccessPolicy" } |
| 133 | + } |
| 134 | + |
| 135 | + class AccessPolicyPermissions extends Object { |
| 136 | + private AccessPolicy accessPolicy; |
| 137 | + |
| 138 | + /** |
| 139 | + * Constructs an AccessPolicyPermissions object for the given access policy. |
| 140 | + */ |
| 141 | + AccessPolicyPermissions() { this = accessPolicy.getProperty("permissions") } |
| 142 | + |
| 143 | + Array getCertificates() { result = this.getProperty("certificates") } |
| 144 | + |
| 145 | + StringLiteral getCertificate(int index) { result = this.getCertificates().getElement(index) } |
| 146 | + |
| 147 | + Array getKeys() { result = this.getProperty("keys") } |
| 148 | + |
| 149 | + StringLiteral getKey(int index) { result = this.getKeys().getElement(index) } |
| 150 | + |
| 151 | + Array getSecrets() { result = this.getProperty("secrets") } |
| 152 | + |
| 153 | + StringLiteral getSecret(int index) { result = this.getSecrets().getElement(index) } |
| 154 | + |
| 155 | + Array getStorages() { result = this.getProperty("storage") } |
| 156 | + |
| 157 | + StringLiteral getStorage(int index) { result = this.getStorages().getElement(index) } |
| 158 | + |
| 159 | + string toString() { result = "AccessPolicyPermissions" } |
| 160 | + } |
| 161 | + } |
| 162 | +} |
0 commit comments