mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 21:51:56 +00:00
Merge branch 'main' into feat/improveSecretReferenceWarning
This commit is contained in:
@@ -10,7 +10,8 @@ export enum SecretSync {
|
||||
TerraformCloud = "terraform-cloud",
|
||||
Camunda = "camunda",
|
||||
Vercel = "vercel",
|
||||
Windmill = "windmill"
|
||||
Windmill = "windmill",
|
||||
TeamCity = "teamcity"
|
||||
}
|
||||
|
||||
export enum SecretSyncInitialSyncBehavior {
|
||||
|
||||
@@ -27,6 +27,7 @@ import { GCP_SYNC_LIST_OPTION } from "./gcp";
|
||||
import { GcpSyncFns } from "./gcp/gcp-sync-fns";
|
||||
import { HUMANITEC_SYNC_LIST_OPTION } from "./humanitec";
|
||||
import { HumanitecSyncFns } from "./humanitec/humanitec-sync-fns";
|
||||
import { TEAMCITY_SYNC_LIST_OPTION, TeamCitySyncFns } from "./teamcity";
|
||||
import { TERRAFORM_CLOUD_SYNC_LIST_OPTION, TerraformCloudSyncFns } from "./terraform-cloud";
|
||||
import { VERCEL_SYNC_LIST_OPTION, VercelSyncFns } from "./vercel";
|
||||
import { WINDMILL_SYNC_LIST_OPTION, WindmillSyncFns } from "./windmill";
|
||||
@@ -43,7 +44,8 @@ const SECRET_SYNC_LIST_OPTIONS: Record<SecretSync, TSecretSyncListItem> = {
|
||||
[SecretSync.TerraformCloud]: TERRAFORM_CLOUD_SYNC_LIST_OPTION,
|
||||
[SecretSync.Camunda]: CAMUNDA_SYNC_LIST_OPTION,
|
||||
[SecretSync.Vercel]: VERCEL_SYNC_LIST_OPTION,
|
||||
[SecretSync.Windmill]: WINDMILL_SYNC_LIST_OPTION
|
||||
[SecretSync.Windmill]: WINDMILL_SYNC_LIST_OPTION,
|
||||
[SecretSync.TeamCity]: TEAMCITY_SYNC_LIST_OPTION
|
||||
};
|
||||
|
||||
export const listSecretSyncOptions = () => {
|
||||
@@ -140,6 +142,8 @@ export const SecretSyncFns = {
|
||||
return VercelSyncFns.syncSecrets(secretSync, secretMap);
|
||||
case SecretSync.Windmill:
|
||||
return WindmillSyncFns.syncSecrets(secretSync, secretMap);
|
||||
case SecretSync.TeamCity:
|
||||
return TeamCitySyncFns.syncSecrets(secretSync, secretMap);
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled sync destination for sync secrets fns: ${(secretSync as TSecretSyncWithCredentials).destination}`
|
||||
@@ -199,6 +203,9 @@ export const SecretSyncFns = {
|
||||
case SecretSync.Windmill:
|
||||
secretMap = await WindmillSyncFns.getSecrets(secretSync);
|
||||
break;
|
||||
case SecretSync.TeamCity:
|
||||
secretMap = await TeamCitySyncFns.getSecrets(secretSync);
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled sync destination for get secrets fns: ${(secretSync as TSecretSyncWithCredentials).destination}`
|
||||
@@ -252,6 +259,8 @@ export const SecretSyncFns = {
|
||||
return VercelSyncFns.removeSecrets(secretSync, secretMap);
|
||||
case SecretSync.Windmill:
|
||||
return WindmillSyncFns.removeSecrets(secretSync, secretMap);
|
||||
case SecretSync.TeamCity:
|
||||
return TeamCitySyncFns.removeSecrets(secretSync, secretMap);
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled sync destination for remove secrets fns: ${(secretSync as TSecretSyncWithCredentials).destination}`
|
||||
|
||||
@@ -13,7 +13,8 @@ export const SECRET_SYNC_NAME_MAP: Record<SecretSync, string> = {
|
||||
[SecretSync.TerraformCloud]: "Terraform Cloud",
|
||||
[SecretSync.Camunda]: "Camunda",
|
||||
[SecretSync.Vercel]: "Vercel",
|
||||
[SecretSync.Windmill]: "Windmill"
|
||||
[SecretSync.Windmill]: "Windmill",
|
||||
[SecretSync.TeamCity]: "TeamCity"
|
||||
};
|
||||
|
||||
export const SECRET_SYNC_CONNECTION_MAP: Record<SecretSync, AppConnection> = {
|
||||
@@ -28,5 +29,6 @@ export const SECRET_SYNC_CONNECTION_MAP: Record<SecretSync, AppConnection> = {
|
||||
[SecretSync.TerraformCloud]: AppConnection.TerraformCloud,
|
||||
[SecretSync.Camunda]: AppConnection.Camunda,
|
||||
[SecretSync.Vercel]: AppConnection.Vercel,
|
||||
[SecretSync.Windmill]: AppConnection.Windmill
|
||||
[SecretSync.Windmill]: AppConnection.Windmill,
|
||||
[SecretSync.TeamCity]: AppConnection.TeamCity
|
||||
};
|
||||
|
||||
@@ -356,8 +356,11 @@ export const secretSyncQueueFactory = ({
|
||||
};
|
||||
|
||||
if (Object.hasOwn(secretMap, key)) {
|
||||
secretsToUpdate.push(secret);
|
||||
if (importBehavior === SecretSyncImportBehavior.PrioritizeDestination) importedSecretMap[key] = secretData;
|
||||
// Only update secrets if the source value is not empty
|
||||
if (value) {
|
||||
secretsToUpdate.push(secret);
|
||||
if (importBehavior === SecretSyncImportBehavior.PrioritizeDestination) importedSecretMap[key] = secretData;
|
||||
}
|
||||
} else {
|
||||
secretsToCreate.push(secret);
|
||||
importedSecretMap[key] = secretData;
|
||||
|
||||
@@ -61,6 +61,12 @@ import {
|
||||
THumanitecSyncListItem,
|
||||
THumanitecSyncWithCredentials
|
||||
} from "./humanitec";
|
||||
import {
|
||||
TTeamCitySync,
|
||||
TTeamCitySyncInput,
|
||||
TTeamCitySyncListItem,
|
||||
TTeamCitySyncWithCredentials
|
||||
} from "./teamcity/teamcity-sync-types";
|
||||
import {
|
||||
TTerraformCloudSync,
|
||||
TTerraformCloudSyncInput,
|
||||
@@ -81,7 +87,8 @@ export type TSecretSync =
|
||||
| TTerraformCloudSync
|
||||
| TCamundaSync
|
||||
| TVercelSync
|
||||
| TWindmillSync;
|
||||
| TWindmillSync
|
||||
| TTeamCitySync;
|
||||
|
||||
export type TSecretSyncWithCredentials =
|
||||
| TAwsParameterStoreSyncWithCredentials
|
||||
@@ -95,7 +102,8 @@ export type TSecretSyncWithCredentials =
|
||||
| TTerraformCloudSyncWithCredentials
|
||||
| TCamundaSyncWithCredentials
|
||||
| TVercelSyncWithCredentials
|
||||
| TWindmillSyncWithCredentials;
|
||||
| TWindmillSyncWithCredentials
|
||||
| TTeamCitySyncWithCredentials;
|
||||
|
||||
export type TSecretSyncInput =
|
||||
| TAwsParameterStoreSyncInput
|
||||
@@ -109,7 +117,8 @@ export type TSecretSyncInput =
|
||||
| TTerraformCloudSyncInput
|
||||
| TCamundaSyncInput
|
||||
| TVercelSyncInput
|
||||
| TWindmillSyncInput;
|
||||
| TWindmillSyncInput
|
||||
| TTeamCitySyncInput;
|
||||
|
||||
export type TSecretSyncListItem =
|
||||
| TAwsParameterStoreSyncListItem
|
||||
@@ -123,7 +132,8 @@ export type TSecretSyncListItem =
|
||||
| TTerraformCloudSyncListItem
|
||||
| TCamundaSyncListItem
|
||||
| TVercelSyncListItem
|
||||
| TWindmillSyncListItem;
|
||||
| TWindmillSyncListItem
|
||||
| TTeamCitySyncListItem;
|
||||
|
||||
export type TSyncOptionsConfig = {
|
||||
canImportSecrets: boolean;
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from "./teamcity-sync-constants";
|
||||
export * from "./teamcity-sync-fns";
|
||||
export * from "./teamcity-sync-schemas";
|
||||
export * from "./teamcity-sync-types";
|
||||
@@ -0,0 +1,10 @@
|
||||
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||
import { SecretSync } from "@app/services/secret-sync/secret-sync-enums";
|
||||
import { TSecretSyncListItem } from "@app/services/secret-sync/secret-sync-types";
|
||||
|
||||
export const TEAMCITY_SYNC_LIST_OPTION: TSecretSyncListItem = {
|
||||
name: "TeamCity",
|
||||
destination: SecretSync.TeamCity,
|
||||
connection: AppConnection.TeamCity,
|
||||
canImportSecrets: true
|
||||
};
|
||||
@@ -0,0 +1,183 @@
|
||||
import { request } from "@app/lib/config/request";
|
||||
import { getTeamCityInstanceUrl } from "@app/services/app-connection/teamcity";
|
||||
import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
|
||||
import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
|
||||
import {
|
||||
TDeleteTeamCityVariable,
|
||||
TPostTeamCityVariable,
|
||||
TTeamCityListVariables,
|
||||
TTeamCityListVariablesResponse,
|
||||
TTeamCitySyncWithCredentials
|
||||
} from "@app/services/secret-sync/teamcity/teamcity-sync-types";
|
||||
|
||||
// Note: Most variables won't be returned with a value due to them being a "password" type (starting with "env.").
|
||||
// TeamCity API returns empty string for password-type variables for security reasons.
|
||||
const listTeamCityVariables = async ({ instanceUrl, accessToken, project, buildConfig }: TTeamCityListVariables) => {
|
||||
const { data } = await request.get<TTeamCityListVariablesResponse>(
|
||||
buildConfig
|
||||
? `${instanceUrl}/app/rest/buildTypes/${encodeURIComponent(buildConfig)}/parameters`
|
||||
: `${instanceUrl}/app/rest/projects/id:${encodeURIComponent(project)}/parameters`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
Accept: "application/json"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Strips out "env." from map key, but the "name" field still has the original unaltered key.
|
||||
return Object.fromEntries(
|
||||
data.property.map((variable) => [
|
||||
variable.name.startsWith("env.") ? variable.name.substring(4) : variable.name,
|
||||
{ ...variable, value: variable.value || "" } // Password values will be empty strings from the API for security
|
||||
])
|
||||
);
|
||||
};
|
||||
|
||||
// Create and update both use the same method
|
||||
const updateTeamCityVariable = async ({
|
||||
instanceUrl,
|
||||
accessToken,
|
||||
project,
|
||||
buildConfig,
|
||||
key,
|
||||
value
|
||||
}: TPostTeamCityVariable) => {
|
||||
return request.post(
|
||||
buildConfig
|
||||
? `${instanceUrl}/app/rest/buildTypes/${encodeURIComponent(buildConfig)}/parameters`
|
||||
: `${instanceUrl}/app/rest/projects/id:${encodeURIComponent(project)}/parameters`,
|
||||
{
|
||||
name: key,
|
||||
value,
|
||||
type: {
|
||||
rawValue: "password display='hidden'"
|
||||
}
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const deleteTeamCityVariable = async ({
|
||||
instanceUrl,
|
||||
accessToken,
|
||||
project,
|
||||
buildConfig,
|
||||
key
|
||||
}: TDeleteTeamCityVariable) => {
|
||||
return request.delete(
|
||||
buildConfig
|
||||
? `${instanceUrl}/app/rest/buildTypes/${encodeURIComponent(buildConfig)}/parameters/${encodeURIComponent(key)}`
|
||||
: `${instanceUrl}/app/rest/projects/id:${encodeURIComponent(project)}/parameters/${encodeURIComponent(key)}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const TeamCitySyncFns = {
|
||||
syncSecrets: async (secretSync: TTeamCitySyncWithCredentials, secretMap: TSecretMap) => {
|
||||
const {
|
||||
connection,
|
||||
destinationConfig: { project, buildConfig }
|
||||
} = secretSync;
|
||||
|
||||
const instanceUrl = await getTeamCityInstanceUrl(connection);
|
||||
const { accessToken } = connection.credentials;
|
||||
|
||||
for await (const entry of Object.entries(secretMap)) {
|
||||
const [key, { value }] = entry;
|
||||
|
||||
const payload = {
|
||||
instanceUrl,
|
||||
accessToken,
|
||||
project,
|
||||
buildConfig,
|
||||
key: `env.${key}`,
|
||||
value
|
||||
};
|
||||
|
||||
try {
|
||||
// Replace every secret since TeamCity does not return secret values that we can cross-check
|
||||
// No need to differenciate create / update because TeamCity uses the same method for both
|
||||
await updateTeamCityVariable(payload);
|
||||
} catch (error) {
|
||||
throw new SecretSyncError({
|
||||
error,
|
||||
secretKey: key
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (secretSync.syncOptions.disableSecretDeletion) return;
|
||||
|
||||
const variables = await listTeamCityVariables({ instanceUrl, accessToken, project, buildConfig });
|
||||
|
||||
for await (const [key, variable] of Object.entries(variables)) {
|
||||
if (!(key in secretMap)) {
|
||||
try {
|
||||
await deleteTeamCityVariable({
|
||||
key: variable.name, // We use variable.name instead of key because key is stripped of "env." prefix in listTeamCityVariables().
|
||||
instanceUrl,
|
||||
accessToken,
|
||||
project,
|
||||
buildConfig
|
||||
});
|
||||
} catch (error) {
|
||||
throw new SecretSyncError({
|
||||
error,
|
||||
secretKey: key
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
removeSecrets: async (secretSync: TTeamCitySyncWithCredentials, secretMap: TSecretMap) => {
|
||||
const {
|
||||
connection,
|
||||
destinationConfig: { project, buildConfig }
|
||||
} = secretSync;
|
||||
|
||||
const instanceUrl = await getTeamCityInstanceUrl(connection);
|
||||
const { accessToken } = connection.credentials;
|
||||
|
||||
const variables = await listTeamCityVariables({ instanceUrl, accessToken, project, buildConfig });
|
||||
|
||||
for await (const [key, variable] of Object.entries(variables)) {
|
||||
if (key in secretMap) {
|
||||
try {
|
||||
await deleteTeamCityVariable({
|
||||
key: variable.name, // We use variable.name instead of key because key is stripped of "env." prefix in listTeamCityVariables().
|
||||
instanceUrl,
|
||||
accessToken,
|
||||
project,
|
||||
buildConfig
|
||||
});
|
||||
} catch (error) {
|
||||
throw new SecretSyncError({
|
||||
error,
|
||||
secretKey: key
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
getSecrets: async (secretSync: TTeamCitySyncWithCredentials) => {
|
||||
const {
|
||||
connection,
|
||||
destinationConfig: { project, buildConfig }
|
||||
} = secretSync;
|
||||
|
||||
const instanceUrl = await getTeamCityInstanceUrl(connection);
|
||||
const { accessToken } = connection.credentials;
|
||||
|
||||
return listTeamCityVariables({ instanceUrl, accessToken, project, buildConfig });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { SecretSyncs } from "@app/lib/api-docs";
|
||||
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||
import { SecretSync } from "@app/services/secret-sync/secret-sync-enums";
|
||||
import {
|
||||
BaseSecretSyncSchema,
|
||||
GenericCreateSecretSyncFieldsSchema,
|
||||
GenericUpdateSecretSyncFieldsSchema
|
||||
} from "@app/services/secret-sync/secret-sync-schemas";
|
||||
import { TSyncOptionsConfig } from "@app/services/secret-sync/secret-sync-types";
|
||||
|
||||
const TeamCitySyncDestinationConfigSchema = z.object({
|
||||
project: z.string().trim().min(1, "Project required").describe(SecretSyncs.DESTINATION_CONFIG.TEAMCITY.project),
|
||||
buildConfig: z.string().trim().optional().describe(SecretSyncs.DESTINATION_CONFIG.TEAMCITY.buildConfig)
|
||||
});
|
||||
|
||||
const TeamCitySyncOptionsConfig: TSyncOptionsConfig = { canImportSecrets: true };
|
||||
|
||||
export const TeamCitySyncSchema = BaseSecretSyncSchema(SecretSync.TeamCity, TeamCitySyncOptionsConfig).extend({
|
||||
destination: z.literal(SecretSync.TeamCity),
|
||||
destinationConfig: TeamCitySyncDestinationConfigSchema
|
||||
});
|
||||
|
||||
export const CreateTeamCitySyncSchema = GenericCreateSecretSyncFieldsSchema(
|
||||
SecretSync.TeamCity,
|
||||
TeamCitySyncOptionsConfig
|
||||
).extend({
|
||||
destinationConfig: TeamCitySyncDestinationConfigSchema
|
||||
});
|
||||
|
||||
export const UpdateTeamCitySyncSchema = GenericUpdateSecretSyncFieldsSchema(
|
||||
SecretSync.TeamCity,
|
||||
TeamCitySyncOptionsConfig
|
||||
).extend({
|
||||
destinationConfig: TeamCitySyncDestinationConfigSchema.optional()
|
||||
});
|
||||
|
||||
export const TeamCitySyncListItemSchema = z.object({
|
||||
name: z.literal("TeamCity"),
|
||||
connection: z.literal(AppConnection.TeamCity),
|
||||
destination: z.literal(SecretSync.TeamCity),
|
||||
canImportSecrets: z.literal(true)
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { TTeamCityConnection } from "@app/services/app-connection/teamcity";
|
||||
|
||||
import { CreateTeamCitySyncSchema, TeamCitySyncListItemSchema, TeamCitySyncSchema } from "./teamcity-sync-schemas";
|
||||
|
||||
export type TTeamCitySync = z.infer<typeof TeamCitySyncSchema>;
|
||||
|
||||
export type TTeamCitySyncInput = z.infer<typeof CreateTeamCitySyncSchema>;
|
||||
|
||||
export type TTeamCitySyncListItem = z.infer<typeof TeamCitySyncListItemSchema>;
|
||||
|
||||
export type TTeamCitySyncWithCredentials = TTeamCitySync & {
|
||||
connection: TTeamCityConnection;
|
||||
};
|
||||
|
||||
export type TTeamCityVariable = {
|
||||
name: string;
|
||||
value: string;
|
||||
inherited?: boolean;
|
||||
type: {
|
||||
rawValue: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type TTeamCityListVariablesResponse = {
|
||||
property: (TTeamCityVariable & { value?: string })[];
|
||||
count: number;
|
||||
href: string;
|
||||
};
|
||||
|
||||
export type TTeamCityListVariables = {
|
||||
accessToken: string;
|
||||
instanceUrl: string;
|
||||
project: string;
|
||||
buildConfig?: string;
|
||||
};
|
||||
|
||||
export type TPostTeamCityVariable = TTeamCityListVariables & {
|
||||
key: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
export type TDeleteTeamCityVariable = TTeamCityListVariables & {
|
||||
key: string;
|
||||
};
|
||||
Reference in New Issue
Block a user