Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Add config option to prefer GET request over LIST when using Hashicorp Vault #8049

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import config from '@/config';
import Container from 'typedi';

export const updateIntervalTime = () => config.getEnv('externalSecrets.updateInterval') * 1000;
export const preferGet = () => config.getEnv('externalSecrets.preferGet');

export function isExternalSecretsEnabled() {
const license = Container.get(License);
Expand Down
9 changes: 7 additions & 2 deletions packages/cli/src/ExternalSecrets/providers/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { AxiosInstance, AxiosResponse } from 'axios';
import axios from 'axios';
import { Logger } from '@/Logger';
import { EXTERNAL_SECRETS_NAME_REGEX } from '../constants';
import { preferGet } from '../externalSecretsHelper.ee';
import { Container } from 'typedi';

type VaultAuthMethod = 'token' | 'usernameAndPassword' | 'appRole';
Expand Down Expand Up @@ -422,10 +423,14 @@ export class VaultProvider extends SecretsProvider {
listPath += path;
let listResp: AxiosResponse<VaultResponse<VaultSecretList>>;
try {
const shouldPreferGet = preferGet();
const url = `${listPath}${shouldPreferGet ? '?list=true' : ''}`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const method = shouldPreferGet ? 'GET' : ('LIST' as any);
listResp = await this.#http.request<VaultResponse<VaultSecretList>>({
url: listPath,
url,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
method: 'LIST' as any,
method,
});
} catch {
return null;
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,12 @@ export const schema = {
env: 'N8N_EXTERNAL_SECRETS_UPDATE_INTERVAL',
doc: 'How often (in seconds) to check for secret updates.',
},
preferGet: {
format: Boolean,
default: false,
env: 'N8N_EXTERNAL_SECRETS_PREFER_GET',
doc: 'Whether to prefer GET over LIST when fetching secrets from Hashicorp Vault.',
},
},

deployment: {
Expand Down
Loading