mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 05:28:29 +00:00
misc: requested changes
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
export const isAzureKeyVaultReference = (uri: string) => {
|
||||||
|
const tryJsonDecode = () => {
|
||||||
|
try {
|
||||||
|
return (JSON.parse(uri) as { uri: string }).uri || uri;
|
||||||
|
} catch {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const cleanUri = tryJsonDecode();
|
||||||
|
|
||||||
|
if (!cleanUri.startsWith("https://")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cleanUri.includes(".vault.azure.net/secrets/")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Check for non-empty string between https:// and .vault.azure.net/secrets/
|
||||||
|
const parts = cleanUri.split(".vault.azure.net/secrets/");
|
||||||
|
const vaultName = parts[0].replace("https://", "");
|
||||||
|
if (!vaultName) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Check for non-empty secret name
|
||||||
|
const secretParts = parts[1].split("/");
|
||||||
|
const secretName = secretParts[0];
|
||||||
|
if (!secretName) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
@@ -46,6 +46,7 @@ import {
|
|||||||
Integrations,
|
Integrations,
|
||||||
IntegrationUrls
|
IntegrationUrls
|
||||||
} from "./integration-list";
|
} from "./integration-list";
|
||||||
|
import { isAzureKeyVaultReference } from "./integration-sync-secret-fns";
|
||||||
|
|
||||||
const getSecretKeyValuePair = (secrets: Record<string, { value: string | null; comment?: string } | null>) =>
|
const getSecretKeyValuePair = (secrets: Record<string, { value: string | null; comment?: string } | null>) =>
|
||||||
Object.keys(secrets).reduce<Record<string, string | null | undefined>>((prev, key) => {
|
Object.keys(secrets).reduce<Record<string, string | null | undefined>>((prev, key) => {
|
||||||
@@ -299,11 +300,6 @@ const syncSecretsAzureAppConfig = async ({
|
|||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format: {\"uri\":\"https://SOME-KEY-VAULT.vault.azure.net/secrets/SOME-SECRET-KEY\"}
|
|
||||||
// Also works without the backslash escapes
|
|
||||||
const azureSecretReferenceUriRegex =
|
|
||||||
/^\{(\\"|")uri(\\"|"):(\\"|")https:\/\/[a-zA-Z0-9-]+\.vault\.azure\.net\/secrets\/[a-zA-Z0-9-]+\\?\2\}$/;
|
|
||||||
|
|
||||||
const getCompleteAzureAppConfigValues = async (url: string) => {
|
const getCompleteAzureAppConfigValues = async (url: string) => {
|
||||||
let result: AzureAppConfigKeyValue[] = [];
|
let result: AzureAppConfigKeyValue[] = [];
|
||||||
while (url) {
|
while (url) {
|
||||||
@@ -325,11 +321,12 @@ const syncSecretsAzureAppConfig = async ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const metadata = IntegrationMetadataSchema.parse(integration.metadata);
|
const metadata = IntegrationMetadataSchema.parse(integration.metadata);
|
||||||
const azureAppConfigSecrets = (
|
|
||||||
await getCompleteAzureAppConfigValues(
|
const azureAppConfigValuesUrl = `${integration.app}/kv?api-version=2023-11-01&key=${metadata.secretPrefix}*${
|
||||||
`${integration.app}/kv?api-version=2023-11-01&key=${metadata.secretPrefix || ""}*`
|
metadata.azureLabel ? `&label=${metadata.azureLabel}` : ""
|
||||||
)
|
}`;
|
||||||
).reduce(
|
|
||||||
|
const azureAppConfigSecrets = (await getCompleteAzureAppConfigValues(azureAppConfigValuesUrl)).reduce(
|
||||||
(accum, entry) => {
|
(accum, entry) => {
|
||||||
accum[entry.key] = entry.value;
|
accum[entry.key] = entry.value;
|
||||||
|
|
||||||
@@ -417,7 +414,7 @@ const syncSecretsAzureAppConfig = async ({
|
|||||||
`${integration.app}/kv/${key}?api-version=2023-11-01`,
|
`${integration.app}/kv/${key}?api-version=2023-11-01`,
|
||||||
{
|
{
|
||||||
value: secrets[key]?.value,
|
value: secrets[key]?.value,
|
||||||
...(azureSecretReferenceUriRegex.test(secrets[key]?.value || "") && {
|
...(isAzureKeyVaultReference(secrets[key]?.value || "") && {
|
||||||
content_type: "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8"
|
content_type: "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8"
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user