mirror of
https://github.com/Infisical/infisical.git
synced 2025-08-24 20:43:19 +00:00
Compare commits
291 Commits
fix/postgr
...
infisical/
Author | SHA1 | Date | |
---|---|---|---|
|
1f6a63fa71 | ||
|
9e76fa8230 | ||
|
e2d4816465 | ||
|
37c8fc80f7 | ||
|
5ca521ea6b | ||
|
40de8331a3 | ||
|
9374ee3c2e | ||
|
561dbb8835 | ||
|
dece214073 | ||
|
992df5c7d0 | ||
|
00e382d774 | ||
|
f63c434c0e | ||
|
9f0250caf2 | ||
|
d47f6f7ec9 | ||
|
1126c6b0fa | ||
|
7949142ea7 | ||
|
122de99606 | ||
|
57fcfdaf21 | ||
|
e430abfc9e | ||
|
7d1bc86702 | ||
|
975b621bc8 | ||
|
ba9da3e6ec | ||
|
d2274a622a | ||
|
41ba7edba2 | ||
|
7acefbca29 | ||
|
e246f6bbfe | ||
|
f265fa6d37 | ||
|
8eebd7228f | ||
|
2a5593ea30 | ||
|
17af33372c | ||
|
27da14df9d | ||
|
cd4b9cd03a | ||
|
0779091d1f | ||
|
c421057cf1 | ||
|
8df4616265 | ||
|
484f34a257 | ||
|
32851565a7 | ||
|
68401a799e | ||
|
0adf2c830d | ||
|
0b7b32bdc3 | ||
|
3400a8f911 | ||
|
e6588b5d0e | ||
|
c68138ac21 | ||
|
608979efa7 | ||
|
585cb1b30c | ||
|
7fdee073d8 | ||
|
d4f0301104 | ||
|
253c46f21d | ||
|
d8e39aed16 | ||
|
c368178cb1 | ||
|
72ee468208 | ||
|
18238b46a7 | ||
|
d0ffae2c10 | ||
|
7ce11cde95 | ||
|
af32948a05 | ||
|
25753fc995 | ||
|
cd71848800 | ||
|
4afc7a1981 | ||
|
11ca76ccca | ||
|
418aca8af0 | ||
|
99e8bdef58 | ||
|
7365f60835 | ||
|
929822514e | ||
|
52ef0e6b81 | ||
|
0f06c4c27a | ||
|
e34deb7bd0 | ||
|
4b6f9fdec2 | ||
|
5df7539f65 | ||
|
616ccb97f2 | ||
|
7917a767e6 | ||
|
ccff675e0d | ||
|
ad905b2ff7 | ||
|
4e960445a4 | ||
|
7af5a4ad8d | ||
|
2ada753527 | ||
|
c031736701 | ||
|
91a1c34637 | ||
|
eadb1a63fa | ||
|
2ff211d235 | ||
|
f70a1e3db6 | ||
|
fc6ab94a06 | ||
|
4feb3314e7 | ||
|
d9a57d1391 | ||
|
2c99d41592 | ||
|
2535d1bc4b | ||
|
83e59ae160 | ||
|
a8a1bc5f4a | ||
|
d2a4f265de | ||
|
3483f185a8 | ||
|
9bc24487b3 | ||
|
4af872e504 | ||
|
716b88fa49 | ||
|
b05ea8a69a | ||
|
0d97bb4c8c | ||
|
cb700c5124 | ||
|
8e829bdf85 | ||
|
716f061c01 | ||
|
5af939992c | ||
|
aec4ee905e | ||
|
dd008724fb | ||
|
dd0c07fb95 | ||
|
d935b28925 | ||
|
60620840f2 | ||
|
e798eb2a4e | ||
|
e96e7b835d | ||
|
75622ed03e | ||
|
a7041fcade | ||
|
0b38fc7843 | ||
|
e678c19874 | ||
|
878e12ea5c | ||
|
485a90bde1 | ||
|
98b6bdad76 | ||
|
f490ca22ac | ||
|
2d8de9e782 | ||
|
14d4cfdbe4 | ||
|
e8bd73c0d0 | ||
|
3406457c08 | ||
|
c16764b62b | ||
|
ab56a69d59 | ||
|
8520ca98c7 | ||
|
95b997c100 | ||
|
b433582ca6 | ||
|
242cfe82c5 | ||
|
60657f0bc6 | ||
|
af4f7ec4f3 | ||
|
454e75cfd0 | ||
|
05408bc151 | ||
|
95f8ae1cf8 | ||
|
feb773152e | ||
|
7f35ff119e | ||
|
cb4cb922b9 | ||
|
dfecaae560 | ||
|
53bec6bc3e | ||
|
af48e7ce99 | ||
|
9f35b573d1 | ||
|
bcb1f35606 | ||
|
67ab16aff3 | ||
|
354aed5e8a | ||
|
e2e9dbc8aa | ||
|
f38b8eac2b | ||
|
7c87feb546 | ||
|
e0cbfe8865 | ||
|
abda494374 | ||
|
272207c580 | ||
|
4cf66a8bfd | ||
|
30ef7f395a | ||
|
ec8ea76e2c | ||
|
cc9f4fb5b3 | ||
|
33256c3462 | ||
|
864be1deb7 | ||
|
f10ab58d74 | ||
|
9ec4419d83 | ||
|
7ff7e5882a | ||
|
e76e0f7bcc | ||
|
cb4999c1b4 | ||
|
79c870530a | ||
|
8b2082f8b5 | ||
|
645e339a23 | ||
|
d4bdf04061 | ||
|
4dcb3938e0 | ||
|
f992535812 | ||
|
464e32b0e9 | ||
|
4547b61d8f | ||
|
047fd9371f | ||
|
0c855f3bd4 | ||
|
bfd8b64871 | ||
|
185cc4efba | ||
|
7150b9314d | ||
|
328f929a29 | ||
|
fa4b133a87 | ||
|
553389af33 | ||
|
4a6e4a90ee | ||
|
ceae1ed0e1 | ||
|
a290ae7767 | ||
|
bdd51d9baf | ||
|
f29593eb60 | ||
|
51d4444c77 | ||
|
1fc217798e | ||
|
7b95d37466 | ||
|
b53504444c | ||
|
193bbf2bf3 | ||
|
5019918516 | ||
|
ce877cd352 | ||
|
d44b3293b6 | ||
|
adb04737e0 | ||
|
42b039af3e | ||
|
2725e4d9dd | ||
|
b719f2d6ba | ||
|
b413f0f49e | ||
|
058dbc144d | ||
|
56eadb25e7 | ||
|
57ce1be0c7 | ||
|
40c1d32621 | ||
|
8399181e3d | ||
|
3c50291cd3 | ||
|
4d8000e331 | ||
|
7884f312cd | ||
|
0dba359f96 | ||
|
de2df991d7 | ||
|
38b9d1f5a5 | ||
|
90c341cf53 | ||
|
80743997e1 | ||
|
f025509938 | ||
|
b7b059bb50 | ||
|
f3a8e30548 | ||
|
b0c93e5c4c | ||
|
4ab0da6b03 | ||
|
9674b71df8 | ||
|
be04d3cf3a | ||
|
b7d7b555b2 | ||
|
8f77a3ae0b | ||
|
a064fae94e | ||
|
954ca58e15 | ||
|
cf6b9d8905 | ||
|
e4a28ab0f4 | ||
|
4ab8d680c4 | ||
|
a3b0d86996 | ||
|
1baa40ac8e | ||
|
277b92ddec | ||
|
0080d5f291 | ||
|
d321f6386d | ||
|
a99e7e24cc | ||
|
a276d27451 | ||
|
cec15d6d51 | ||
|
007e10d409 | ||
|
a8b448be0f | ||
|
bfda3776ee | ||
|
e71911c2de | ||
|
f2513b0f17 | ||
|
d0e7af721e | ||
|
c5c2e2619e | ||
|
8df53dde3b | ||
|
394ecd24a0 | ||
|
6d3acb5514 | ||
|
bc98c42c79 | ||
|
e6bfb6ce2b | ||
|
1c20e4fef0 | ||
|
b560cdb0f8 | ||
|
144143b43a | ||
|
b9a05688cd | ||
|
c06c6c6c61 | ||
|
350afee45e | ||
|
5ae18a691d | ||
|
8187b1da91 | ||
|
0174d36136 | ||
|
968d7420c6 | ||
|
fd761df8e5 | ||
|
61ca617616 | ||
|
1e08b3cdc2 | ||
|
844f2bb72c | ||
|
6ce6c276cd | ||
|
32b2f7b0fe | ||
|
4c2823c480 | ||
|
60438694e4 | ||
|
fdaf8f9a87 | ||
|
3fe41f81fe | ||
|
c1798d37be | ||
|
01c6d3192d | ||
|
621bfe3e60 | ||
|
67ec00d46b | ||
|
d6c2789d46 | ||
|
58ba0c8ed4 | ||
|
f38c574030 | ||
|
c330d8ca8a | ||
|
2cb0ecc768 | ||
|
ecc15bb432 | ||
|
59c0f1ff08 | ||
|
5110d59bea | ||
|
0e07ebae7b | ||
|
cd84d57025 | ||
|
19cb220107 | ||
|
fce6738562 | ||
|
aab204a68a | ||
|
49afaa4d2d | ||
|
a94a26263a | ||
|
2f9baee210 | ||
|
bd7947c04e | ||
|
7ff8a19518 | ||
|
bd4968b60d | ||
|
08dfaaa8b0 | ||
|
6449699f03 | ||
|
221de8beb4 | ||
|
0e680e366b | ||
|
0af00ce82d | ||
|
3153450dc5 | ||
|
50ba2e543c | ||
|
6bb634f5ed | ||
|
706447d5c6 | ||
|
246fe81134 | ||
|
e2559f10bc | ||
|
0efc314f33 |
13
.env.example
13
.env.example
@@ -123,8 +123,17 @@ INF_APP_CONNECTION_GITHUB_RADAR_APP_WEBHOOK_SECRET=
|
|||||||
INF_APP_CONNECTION_GCP_SERVICE_ACCOUNT_CREDENTIAL=
|
INF_APP_CONNECTION_GCP_SERVICE_ACCOUNT_CREDENTIAL=
|
||||||
|
|
||||||
# azure app connection
|
# azure app connection
|
||||||
INF_APP_CONNECTION_AZURE_CLIENT_ID=
|
INF_APP_CONNECTION_AZURE_APP_CONFIGURATION_CLIENT_ID=
|
||||||
INF_APP_CONNECTION_AZURE_CLIENT_SECRET=
|
INF_APP_CONNECTION_AZURE_APP_CONFIGURATION_CLIENT_SECRET=
|
||||||
|
|
||||||
|
INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_ID=
|
||||||
|
INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_SECRET=
|
||||||
|
|
||||||
|
INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_ID=
|
||||||
|
INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_SECRET=
|
||||||
|
|
||||||
|
INF_APP_CONNECTION_AZURE_DEVOPS_CLIENT_ID=
|
||||||
|
INF_APP_CONNECTION_AZURE_DEVOPS_CLIENT_SECRET=
|
||||||
|
|
||||||
# datadog
|
# datadog
|
||||||
SHOULD_USE_DATADOG_TRACER=
|
SHOULD_USE_DATADOG_TRACER=
|
||||||
|
153
.github/workflows/release_build_infisical_cli.yml
vendored
153
.github/workflows/release_build_infisical_cli.yml
vendored
@@ -1,153 +0,0 @@
|
|||||||
name: Build and release CLI
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
push:
|
|
||||||
# run only against tags
|
|
||||||
tags:
|
|
||||||
- "infisical-cli/v*.*.*"
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
cli-integration-tests:
|
|
||||||
name: Run tests before deployment
|
|
||||||
uses: ./.github/workflows/run-cli-tests.yml
|
|
||||||
secrets:
|
|
||||||
CLI_TESTS_UA_CLIENT_ID: ${{ secrets.CLI_TESTS_UA_CLIENT_ID }}
|
|
||||||
CLI_TESTS_UA_CLIENT_SECRET: ${{ secrets.CLI_TESTS_UA_CLIENT_SECRET }}
|
|
||||||
CLI_TESTS_SERVICE_TOKEN: ${{ secrets.CLI_TESTS_SERVICE_TOKEN }}
|
|
||||||
CLI_TESTS_PROJECT_ID: ${{ secrets.CLI_TESTS_PROJECT_ID }}
|
|
||||||
CLI_TESTS_ENV_SLUG: ${{ secrets.CLI_TESTS_ENV_SLUG }}
|
|
||||||
CLI_TESTS_USER_EMAIL: ${{ secrets.CLI_TESTS_USER_EMAIL }}
|
|
||||||
CLI_TESTS_USER_PASSWORD: ${{ secrets.CLI_TESTS_USER_PASSWORD }}
|
|
||||||
CLI_TESTS_INFISICAL_VAULT_FILE_PASSPHRASE: ${{ secrets.CLI_TESTS_INFISICAL_VAULT_FILE_PASSPHRASE }}
|
|
||||||
|
|
||||||
npm-release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
working-directory: ./npm
|
|
||||||
needs:
|
|
||||||
- cli-integration-tests
|
|
||||||
- goreleaser
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Extract version
|
|
||||||
run: |
|
|
||||||
VERSION=$(echo ${{ github.ref_name }} | sed 's/infisical-cli\/v//')
|
|
||||||
echo "Version extracted: $VERSION"
|
|
||||||
echo "CLI_VERSION=$VERSION" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Print version
|
|
||||||
run: echo ${{ env.CLI_VERSION }}
|
|
||||||
|
|
||||||
- name: Setup Node
|
|
||||||
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
cache: "npm"
|
|
||||||
cache-dependency-path: ./npm/package-lock.json
|
|
||||||
- name: Install dependencies
|
|
||||||
working-directory: ${{ env.working-directory }}
|
|
||||||
run: npm install --ignore-scripts
|
|
||||||
|
|
||||||
- name: Set NPM version
|
|
||||||
working-directory: ${{ env.working-directory }}
|
|
||||||
run: npm version ${{ env.CLI_VERSION }} --allow-same-version --no-git-tag-version
|
|
||||||
|
|
||||||
- name: Setup NPM
|
|
||||||
working-directory: ${{ env.working-directory }}
|
|
||||||
run: |
|
|
||||||
echo 'registry="https://registry.npmjs.org/"' > ./.npmrc
|
|
||||||
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ./.npmrc
|
|
||||||
|
|
||||||
echo 'registry="https://registry.npmjs.org/"' > ~/.npmrc
|
|
||||||
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
|
|
||||||
env:
|
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
||||||
|
|
||||||
- name: Pack NPM
|
|
||||||
working-directory: ${{ env.working-directory }}
|
|
||||||
run: npm pack
|
|
||||||
|
|
||||||
- name: Publish NPM
|
|
||||||
working-directory: ${{ env.working-directory }}
|
|
||||||
run: npm publish --tarball=./infisical-sdk-${{github.ref_name}} --access public --registry=https://registry.npmjs.org/
|
|
||||||
env:
|
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
||||||
|
|
||||||
goreleaser:
|
|
||||||
runs-on: ubuntu-latest-8-cores
|
|
||||||
needs: [cli-integration-tests]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: 🐋 Login to Docker Hub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
- name: 🔧 Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
- run: git fetch --force --tags
|
|
||||||
- run: echo "Ref name ${{github.ref_name}}"
|
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: ">=1.19.3"
|
|
||||||
cache: true
|
|
||||||
cache-dependency-path: cli/go.sum
|
|
||||||
- name: Setup for libssl1.0-dev
|
|
||||||
run: |
|
|
||||||
echo 'deb http://security.ubuntu.com/ubuntu bionic-security main' | sudo tee -a /etc/apt/sources.list
|
|
||||||
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
|
|
||||||
sudo apt update
|
|
||||||
sudo apt-get install -y libssl1.0-dev
|
|
||||||
- name: OSXCross for CGO Support
|
|
||||||
run: |
|
|
||||||
mkdir ../../osxcross
|
|
||||||
git clone https://github.com/plentico/osxcross-target.git ../../osxcross/target
|
|
||||||
- uses: goreleaser/goreleaser-action@v4
|
|
||||||
with:
|
|
||||||
distribution: goreleaser-pro
|
|
||||||
version: v1.26.2-pro
|
|
||||||
args: release --clean
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
|
|
||||||
POSTHOG_API_KEY_FOR_CLI: ${{ secrets.POSTHOG_API_KEY_FOR_CLI }}
|
|
||||||
FURY_TOKEN: ${{ secrets.FURYPUSHTOKEN }}
|
|
||||||
AUR_KEY: ${{ secrets.AUR_KEY }}
|
|
||||||
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
|
|
||||||
- uses: actions/setup-python@v4
|
|
||||||
- run: pip install --upgrade cloudsmith-cli
|
|
||||||
- uses: ruby/setup-ruby@354a1ad156761f5ee2b7b13fa8e09943a5e8d252
|
|
||||||
with:
|
|
||||||
ruby-version: "3.3" # Not needed with a .ruby-version, .tool-versions or mise.toml
|
|
||||||
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
||||||
- name: Install deb-s3
|
|
||||||
run: gem install deb-s3
|
|
||||||
- name: Configure GPG Key
|
|
||||||
run: echo -n "$GPG_SIGNING_KEY" | base64 --decode | gpg --batch --import
|
|
||||||
env:
|
|
||||||
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
|
|
||||||
GPG_SIGNING_KEY_PASSPHRASE: ${{ secrets.GPG_SIGNING_KEY_PASSPHRASE }}
|
|
||||||
- name: Publish to CloudSmith
|
|
||||||
run: sh cli/upload_to_cloudsmith.sh
|
|
||||||
env:
|
|
||||||
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
|
|
||||||
INFISICAL_CLI_S3_BUCKET: ${{ secrets.INFISICAL_CLI_S3_BUCKET }}
|
|
||||||
INFISICAL_CLI_REPO_SIGNING_KEY_ID: ${{ secrets.INFISICAL_CLI_REPO_SIGNING_KEY_ID }}
|
|
||||||
AWS_ACCESS_KEY_ID: ${{ secrets.INFISICAL_CLI_REPO_AWS_ACCESS_KEY_ID }}
|
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.INFISICAL_CLI_REPO_AWS_SECRET_ACCESS_KEY }}
|
|
||||||
- name: Invalidate Cloudfront cache
|
|
||||||
run: aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths '/deb/dists/stable/*'
|
|
||||||
env:
|
|
||||||
AWS_ACCESS_KEY_ID: ${{ secrets.INFISICAL_CLI_REPO_AWS_ACCESS_KEY_ID }}
|
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.INFISICAL_CLI_REPO_AWS_SECRET_ACCESS_KEY }}
|
|
||||||
CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.INFISICAL_CLI_REPO_CLOUDFRONT_DISTRIBUTION_ID }}
|
|
55
.github/workflows/run-cli-tests.yml
vendored
55
.github/workflows/run-cli-tests.yml
vendored
@@ -1,55 +0,0 @@
|
|||||||
name: Go CLI Tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [opened, synchronize]
|
|
||||||
paths:
|
|
||||||
- "cli/**"
|
|
||||||
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
workflow_call:
|
|
||||||
secrets:
|
|
||||||
CLI_TESTS_UA_CLIENT_ID:
|
|
||||||
required: true
|
|
||||||
CLI_TESTS_UA_CLIENT_SECRET:
|
|
||||||
required: true
|
|
||||||
CLI_TESTS_SERVICE_TOKEN:
|
|
||||||
required: true
|
|
||||||
CLI_TESTS_PROJECT_ID:
|
|
||||||
required: true
|
|
||||||
CLI_TESTS_ENV_SLUG:
|
|
||||||
required: true
|
|
||||||
CLI_TESTS_USER_EMAIL:
|
|
||||||
required: true
|
|
||||||
CLI_TESTS_USER_PASSWORD:
|
|
||||||
required: true
|
|
||||||
CLI_TESTS_INFISICAL_VAULT_FILE_PASSPHRASE:
|
|
||||||
required: true
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: ./cli
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v4
|
|
||||||
with:
|
|
||||||
go-version: "1.21.x"
|
|
||||||
- name: Install dependencies
|
|
||||||
run: go get .
|
|
||||||
- name: Test with the Go CLI
|
|
||||||
env:
|
|
||||||
CLI_TESTS_UA_CLIENT_ID: ${{ secrets.CLI_TESTS_UA_CLIENT_ID }}
|
|
||||||
CLI_TESTS_UA_CLIENT_SECRET: ${{ secrets.CLI_TESTS_UA_CLIENT_SECRET }}
|
|
||||||
CLI_TESTS_SERVICE_TOKEN: ${{ secrets.CLI_TESTS_SERVICE_TOKEN }}
|
|
||||||
CLI_TESTS_PROJECT_ID: ${{ secrets.CLI_TESTS_PROJECT_ID }}
|
|
||||||
CLI_TESTS_ENV_SLUG: ${{ secrets.CLI_TESTS_ENV_SLUG }}
|
|
||||||
CLI_TESTS_USER_EMAIL: ${{ secrets.CLI_TESTS_USER_EMAIL }}
|
|
||||||
CLI_TESTS_USER_PASSWORD: ${{ secrets.CLI_TESTS_USER_PASSWORD }}
|
|
||||||
# INFISICAL_VAULT_FILE_PASSPHRASE: ${{ secrets.CLI_TESTS_INFISICAL_VAULT_FILE_PASSPHRASE }}
|
|
||||||
|
|
||||||
run: go test -v -count=1 ./test
|
|
241
.goreleaser.yaml
241
.goreleaser.yaml
@@ -1,241 +0,0 @@
|
|||||||
# This is an example .goreleaser.yml file with some sensible defaults.
|
|
||||||
# Make sure to check the documentation at https://goreleaser.com
|
|
||||||
# before:
|
|
||||||
# hooks:
|
|
||||||
# # You may remove this if you don't use go modules.
|
|
||||||
# - cd cli && go mod tidy
|
|
||||||
# # you may remove this if you don't need go generate
|
|
||||||
# - cd cli && go generate ./...
|
|
||||||
before:
|
|
||||||
hooks:
|
|
||||||
- ./cli/scripts/completions.sh
|
|
||||||
- ./cli/scripts/manpages.sh
|
|
||||||
|
|
||||||
monorepo:
|
|
||||||
tag_prefix: infisical-cli/
|
|
||||||
dir: cli
|
|
||||||
|
|
||||||
builds:
|
|
||||||
- id: darwin-build
|
|
||||||
binary: infisical
|
|
||||||
ldflags:
|
|
||||||
- -X github.com/Infisical/infisical-merge/packages/util.CLI_VERSION={{ .Version }}
|
|
||||||
- -X github.com/Infisical/infisical-merge/packages/telemetry.POSTHOG_API_KEY_FOR_CLI={{ .Env.POSTHOG_API_KEY_FOR_CLI }}
|
|
||||||
flags:
|
|
||||||
- -trimpath
|
|
||||||
env:
|
|
||||||
- CGO_ENABLED=1
|
|
||||||
- CC=/home/runner/work/osxcross/target/bin/o64-clang
|
|
||||||
- CXX=/home/runner/work/osxcross/target/bin/o64-clang++
|
|
||||||
goos:
|
|
||||||
- darwin
|
|
||||||
ignore:
|
|
||||||
- goos: darwin
|
|
||||||
goarch: "386"
|
|
||||||
dir: ./cli
|
|
||||||
|
|
||||||
- id: all-other-builds
|
|
||||||
env:
|
|
||||||
- CGO_ENABLED=0
|
|
||||||
binary: infisical
|
|
||||||
ldflags:
|
|
||||||
- -X github.com/Infisical/infisical-merge/packages/util.CLI_VERSION={{ .Version }}
|
|
||||||
- -X github.com/Infisical/infisical-merge/packages/telemetry.POSTHOG_API_KEY_FOR_CLI={{ .Env.POSTHOG_API_KEY_FOR_CLI }}
|
|
||||||
flags:
|
|
||||||
- -trimpath
|
|
||||||
goos:
|
|
||||||
- freebsd
|
|
||||||
- linux
|
|
||||||
- netbsd
|
|
||||||
- openbsd
|
|
||||||
- windows
|
|
||||||
goarch:
|
|
||||||
- "386"
|
|
||||||
- amd64
|
|
||||||
- arm
|
|
||||||
- arm64
|
|
||||||
goarm:
|
|
||||||
- "6"
|
|
||||||
- "7"
|
|
||||||
ignore:
|
|
||||||
- goos: windows
|
|
||||||
goarch: "386"
|
|
||||||
- goos: freebsd
|
|
||||||
goarch: "386"
|
|
||||||
dir: ./cli
|
|
||||||
|
|
||||||
archives:
|
|
||||||
- format_overrides:
|
|
||||||
- goos: windows
|
|
||||||
format: zip
|
|
||||||
files:
|
|
||||||
- ../README*
|
|
||||||
- ../LICENSE*
|
|
||||||
- ../manpages/*
|
|
||||||
- ../completions/*
|
|
||||||
|
|
||||||
release:
|
|
||||||
replace_existing_draft: true
|
|
||||||
mode: "replace"
|
|
||||||
|
|
||||||
checksum:
|
|
||||||
name_template: "checksums.txt"
|
|
||||||
|
|
||||||
snapshot:
|
|
||||||
name_template: "{{ .Version }}-devel"
|
|
||||||
|
|
||||||
# publishers:
|
|
||||||
# - name: fury.io
|
|
||||||
# ids:
|
|
||||||
# - infisical
|
|
||||||
# dir: "{{ dir .ArtifactPath }}"
|
|
||||||
# cmd: curl -F package=@{{ .ArtifactName }} https://{{ .Env.FURY_TOKEN }}@push.fury.io/infisical/
|
|
||||||
|
|
||||||
brews:
|
|
||||||
- name: infisical
|
|
||||||
tap:
|
|
||||||
owner: Infisical
|
|
||||||
name: homebrew-get-cli
|
|
||||||
commit_author:
|
|
||||||
name: "Infisical"
|
|
||||||
email: ai@infisical.com
|
|
||||||
folder: Formula
|
|
||||||
homepage: "https://infisical.com"
|
|
||||||
description: "The official Infisical CLI"
|
|
||||||
install: |-
|
|
||||||
bin.install "infisical"
|
|
||||||
bash_completion.install "completions/infisical.bash" => "infisical"
|
|
||||||
zsh_completion.install "completions/infisical.zsh" => "_infisical"
|
|
||||||
fish_completion.install "completions/infisical.fish"
|
|
||||||
man1.install "manpages/infisical.1.gz"
|
|
||||||
- name: "infisical@{{.Version}}"
|
|
||||||
tap:
|
|
||||||
owner: Infisical
|
|
||||||
name: homebrew-get-cli
|
|
||||||
commit_author:
|
|
||||||
name: "Infisical"
|
|
||||||
email: ai@infisical.com
|
|
||||||
folder: Formula
|
|
||||||
homepage: "https://infisical.com"
|
|
||||||
description: "The official Infisical CLI"
|
|
||||||
install: |-
|
|
||||||
bin.install "infisical"
|
|
||||||
bash_completion.install "completions/infisical.bash" => "infisical"
|
|
||||||
zsh_completion.install "completions/infisical.zsh" => "_infisical"
|
|
||||||
fish_completion.install "completions/infisical.fish"
|
|
||||||
man1.install "manpages/infisical.1.gz"
|
|
||||||
|
|
||||||
nfpms:
|
|
||||||
- id: infisical
|
|
||||||
package_name: infisical
|
|
||||||
builds:
|
|
||||||
- all-other-builds
|
|
||||||
vendor: Infisical, Inc
|
|
||||||
homepage: https://infisical.com/
|
|
||||||
maintainer: Infisical, Inc
|
|
||||||
description: The offical Infisical CLI
|
|
||||||
license: MIT
|
|
||||||
formats:
|
|
||||||
- rpm
|
|
||||||
- deb
|
|
||||||
- apk
|
|
||||||
- archlinux
|
|
||||||
bindir: /usr/bin
|
|
||||||
contents:
|
|
||||||
- src: ./completions/infisical.bash
|
|
||||||
dst: /etc/bash_completion.d/infisical
|
|
||||||
- src: ./completions/infisical.fish
|
|
||||||
dst: /usr/share/fish/vendor_completions.d/infisical.fish
|
|
||||||
- src: ./completions/infisical.zsh
|
|
||||||
dst: /usr/share/zsh/site-functions/_infisical
|
|
||||||
- src: ./manpages/infisical.1.gz
|
|
||||||
dst: /usr/share/man/man1/infisical.1.gz
|
|
||||||
|
|
||||||
scoop:
|
|
||||||
bucket:
|
|
||||||
owner: Infisical
|
|
||||||
name: scoop-infisical
|
|
||||||
commit_author:
|
|
||||||
name: "Infisical"
|
|
||||||
email: ai@infisical.com
|
|
||||||
homepage: "https://infisical.com"
|
|
||||||
description: "The official Infisical CLI"
|
|
||||||
license: MIT
|
|
||||||
|
|
||||||
winget:
|
|
||||||
- name: infisical
|
|
||||||
publisher: infisical
|
|
||||||
license: MIT
|
|
||||||
homepage: https://infisical.com
|
|
||||||
short_description: "The official Infisical CLI"
|
|
||||||
repository:
|
|
||||||
owner: infisical
|
|
||||||
name: winget-pkgs
|
|
||||||
branch: "infisical-{{.Version}}"
|
|
||||||
pull_request:
|
|
||||||
enabled: true
|
|
||||||
draft: false
|
|
||||||
base:
|
|
||||||
owner: microsoft
|
|
||||||
name: winget-pkgs
|
|
||||||
branch: master
|
|
||||||
|
|
||||||
aurs:
|
|
||||||
- name: infisical-bin
|
|
||||||
homepage: "https://infisical.com"
|
|
||||||
description: "The official Infisical CLI"
|
|
||||||
maintainers:
|
|
||||||
- Infisical, Inc <support@infisical.com>
|
|
||||||
license: MIT
|
|
||||||
private_key: "{{ .Env.AUR_KEY }}"
|
|
||||||
git_url: "ssh://aur@aur.archlinux.org/infisical-bin.git"
|
|
||||||
package: |-
|
|
||||||
# bin
|
|
||||||
install -Dm755 "./infisical" "${pkgdir}/usr/bin/infisical"
|
|
||||||
# license
|
|
||||||
install -Dm644 "./LICENSE" "${pkgdir}/usr/share/licenses/infisical/LICENSE"
|
|
||||||
# completions
|
|
||||||
mkdir -p "${pkgdir}/usr/share/bash-completion/completions/"
|
|
||||||
mkdir -p "${pkgdir}/usr/share/zsh/site-functions/"
|
|
||||||
mkdir -p "${pkgdir}/usr/share/fish/vendor_completions.d/"
|
|
||||||
install -Dm644 "./completions/infisical.bash" "${pkgdir}/usr/share/bash-completion/completions/infisical"
|
|
||||||
install -Dm644 "./completions/infisical.zsh" "${pkgdir}/usr/share/zsh/site-functions/_infisical"
|
|
||||||
install -Dm644 "./completions/infisical.fish" "${pkgdir}/usr/share/fish/vendor_completions.d/infisical.fish"
|
|
||||||
# man pages
|
|
||||||
install -Dm644 "./manpages/infisical.1.gz" "${pkgdir}/usr/share/man/man1/infisical.1.gz"
|
|
||||||
|
|
||||||
dockers:
|
|
||||||
- dockerfile: docker/alpine
|
|
||||||
goos: linux
|
|
||||||
goarch: amd64
|
|
||||||
use: buildx
|
|
||||||
ids:
|
|
||||||
- all-other-builds
|
|
||||||
image_templates:
|
|
||||||
- "infisical/cli:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
|
|
||||||
- "infisical/cli:latest-amd64"
|
|
||||||
build_flag_templates:
|
|
||||||
- "--pull"
|
|
||||||
- "--platform=linux/amd64"
|
|
||||||
- dockerfile: docker/alpine
|
|
||||||
goos: linux
|
|
||||||
goarch: amd64
|
|
||||||
use: buildx
|
|
||||||
ids:
|
|
||||||
- all-other-builds
|
|
||||||
image_templates:
|
|
||||||
- "infisical/cli:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
|
|
||||||
- "infisical/cli:latest-arm64"
|
|
||||||
build_flag_templates:
|
|
||||||
- "--pull"
|
|
||||||
- "--platform=linux/arm64"
|
|
||||||
|
|
||||||
docker_manifests:
|
|
||||||
- name_template: "infisical/cli:{{ .Major }}.{{ .Minor }}.{{ .Patch }}"
|
|
||||||
image_templates:
|
|
||||||
- "infisical/cli:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-amd64"
|
|
||||||
- "infisical/cli:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-arm64"
|
|
||||||
- name_template: "infisical/cli:latest"
|
|
||||||
image_templates:
|
|
||||||
- "infisical/cli:latest-amd64"
|
|
||||||
- "infisical/cli:latest-arm64"
|
|
@@ -34,6 +34,8 @@ ENV VITE_INFISICAL_PLATFORM_VERSION $INFISICAL_PLATFORM_VERSION
|
|||||||
ARG CAPTCHA_SITE_KEY
|
ARG CAPTCHA_SITE_KEY
|
||||||
ENV VITE_CAPTCHA_SITE_KEY $CAPTCHA_SITE_KEY
|
ENV VITE_CAPTCHA_SITE_KEY $CAPTCHA_SITE_KEY
|
||||||
|
|
||||||
|
ENV NODE_OPTIONS="--max-old-space-size=8192"
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
@@ -145,7 +147,11 @@ RUN wget https://www.openssl.org/source/openssl-3.1.2.tar.gz \
|
|||||||
&& cd openssl-3.1.2 \
|
&& cd openssl-3.1.2 \
|
||||||
&& ./Configure enable-fips \
|
&& ./Configure enable-fips \
|
||||||
&& make \
|
&& make \
|
||||||
&& make install_fips
|
&& make install_fips \
|
||||||
|
&& cd / \
|
||||||
|
&& rm -rf /openssl-build \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
# Install Infisical CLI
|
# Install Infisical CLI
|
||||||
RUN curl -1sLf 'https://artifacts-cli.infisical.com/setup.deb.sh' | bash \
|
RUN curl -1sLf 'https://artifacts-cli.infisical.com/setup.deb.sh' | bash \
|
||||||
@@ -186,12 +192,11 @@ ENV NODE_ENV production
|
|||||||
ENV STANDALONE_BUILD true
|
ENV STANDALONE_BUILD true
|
||||||
ENV STANDALONE_MODE true
|
ENV STANDALONE_MODE true
|
||||||
ENV ChrystokiConfigurationPath=/usr/safenet/lunaclient/
|
ENV ChrystokiConfigurationPath=/usr/safenet/lunaclient/
|
||||||
ENV NODE_OPTIONS="--max-old-space-size=1024"
|
ENV NODE_OPTIONS="--max-old-space-size=8192 --force-fips"
|
||||||
|
|
||||||
# FIPS mode of operation:
|
# FIPS mode of operation:
|
||||||
ENV OPENSSL_CONF=/backend/nodejs.fips.cnf
|
ENV OPENSSL_CONF=/backend/nodejs.fips.cnf
|
||||||
ENV OPENSSL_MODULES=/usr/local/lib/ossl-modules
|
ENV OPENSSL_MODULES=/usr/local/lib/ossl-modules
|
||||||
ENV NODE_OPTIONS=--force-fips
|
|
||||||
ENV FIPS_ENABLED=true
|
ENV FIPS_ENABLED=true
|
||||||
|
|
||||||
|
|
||||||
@@ -206,6 +211,11 @@ EXPOSE 443
|
|||||||
RUN grep -v 'import "./lib/telemetry/instrumentation.mjs";' dist/main.mjs > dist/main.mjs.tmp && \
|
RUN grep -v 'import "./lib/telemetry/instrumentation.mjs";' dist/main.mjs > dist/main.mjs.tmp && \
|
||||||
mv dist/main.mjs.tmp dist/main.mjs
|
mv dist/main.mjs.tmp dist/main.mjs
|
||||||
|
|
||||||
|
# The OpenSSL library is installed in different locations in different architectures (x86_64 and arm64).
|
||||||
|
# This is a workaround to avoid errors when the library is not found.
|
||||||
|
RUN ln -sf /usr/local/lib64/ossl-modules /usr/local/lib/ossl-modules || \
|
||||||
|
ln -sf /usr/local/lib/ossl-modules /usr/local/lib64/ossl-modules
|
||||||
|
|
||||||
USER non-root-user
|
USER non-root-user
|
||||||
|
|
||||||
CMD ["./standalone-entrypoint.sh"]
|
CMD ["./standalone-entrypoint.sh"]
|
11
README.md
11
README.md
@@ -149,11 +149,8 @@ Not sure where to get started? You can:
|
|||||||
|
|
||||||
- Join our <a href="https://infisical.com/slack">Slack</a>, and ask us any questions there.
|
- Join our <a href="https://infisical.com/slack">Slack</a>, and ask us any questions there.
|
||||||
|
|
||||||
## Resources
|
## We are hiring!
|
||||||
|
|
||||||
- [Docs](https://infisical.com/docs/documentation/getting-started/introduction) for comprehensive documentation and guides
|
If you're reading this, there is a strong chance you like the products we created.
|
||||||
- [Slack](https://infisical.com/slack) for discussion with the community and Infisical team.
|
|
||||||
- [GitHub](https://github.com/Infisical/infisical) for code, issues, and pull requests
|
You might also make a great addition to our team. We're growing fast and would love for you to [join us](https://infisical.com/careers).
|
||||||
- [Twitter](https://twitter.com/infisical) for fast news
|
|
||||||
- [YouTube](https://www.youtube.com/@infisical_os) for videos on secret management
|
|
||||||
- [Blog](https://infisical.com/blog) for secret management insights, articles, tutorials, and updates
|
|
||||||
|
@@ -59,7 +59,11 @@ RUN wget https://www.openssl.org/source/openssl-3.1.2.tar.gz \
|
|||||||
&& cd openssl-3.1.2 \
|
&& cd openssl-3.1.2 \
|
||||||
&& ./Configure enable-fips \
|
&& ./Configure enable-fips \
|
||||||
&& make \
|
&& make \
|
||||||
&& make install_fips
|
&& make install_fips \
|
||||||
|
&& cd / \
|
||||||
|
&& rm -rf /openssl-build \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
# ? App setup
|
# ? App setup
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@ export const mockQueue = (): TQueueServiceFactory => {
|
|||||||
events[name] = event;
|
events[name] = event;
|
||||||
},
|
},
|
||||||
getRepeatableJobs: async () => [],
|
getRepeatableJobs: async () => [],
|
||||||
|
getDelayedJobs: async () => [],
|
||||||
clearQueue: async () => {},
|
clearQueue: async () => {},
|
||||||
stopJobById: async () => {},
|
stopJobById: async () => {},
|
||||||
stopJobByIdPg: async () => {},
|
stopJobByIdPg: async () => {},
|
||||||
|
31
backend/package-lock.json
generated
31
backend/package-lock.json
generated
@@ -7,6 +7,7 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "backend",
|
"name": "backend",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
"hasInstallScript": true,
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-elasticache": "^3.637.0",
|
"@aws-sdk/client-elasticache": "^3.637.0",
|
||||||
@@ -61,7 +62,7 @@
|
|||||||
"ajv": "^8.12.0",
|
"ajv": "^8.12.0",
|
||||||
"argon2": "^0.31.2",
|
"argon2": "^0.31.2",
|
||||||
"aws-sdk": "^2.1553.0",
|
"aws-sdk": "^2.1553.0",
|
||||||
"axios": "^1.6.7",
|
"axios": "^1.11.0",
|
||||||
"axios-retry": "^4.0.0",
|
"axios-retry": "^4.0.0",
|
||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"botbuilder": "^4.23.2",
|
"botbuilder": "^4.23.2",
|
||||||
@@ -13699,14 +13700,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/request/node_modules/form-data": {
|
"node_modules/@types/request/node_modules/form-data": {
|
||||||
"version": "2.5.2",
|
"version": "2.5.5",
|
||||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.5.tgz",
|
||||||
"integrity": "sha512-GgwY0PS7DbXqajuGf4OYlsrIu3zgxD6Vvql43IBhm6MahqA5SK/7mwhtNj2AdH2z35YR34ujJ7BN+3fFC3jP5Q==",
|
"integrity": "sha512-jqdObeR2rxZZbPSGL+3VckHMYtu+f9//KXBsVny6JSX/pa38Fy+bGjuG8eW/H6USNQWhLi8Num++cU2yOCNz4A==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"asynckit": "^0.4.0",
|
"asynckit": "^0.4.0",
|
||||||
"combined-stream": "^1.0.6",
|
"combined-stream": "^1.0.8",
|
||||||
"mime-types": "^2.1.12",
|
"es-set-tostringtag": "^2.1.0",
|
||||||
|
"hasown": "^2.0.2",
|
||||||
|
"mime-types": "^2.1.35",
|
||||||
"safe-buffer": "^5.2.1"
|
"safe-buffer": "^5.2.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -15230,13 +15233,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
"node_modules/axios": {
|
||||||
"version": "1.7.9",
|
"version": "1.11.0",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.11.0.tgz",
|
||||||
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
|
"integrity": "sha512-1Lx3WLFQWm3ooKDYZD1eXmoGO9fxYQjrycfHFC8P0sCfQVXyROp0p9PFWBehewBOdCwHc+f/b8I0fMto5eSfwA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.15.6",
|
"follow-redirects": "^1.15.6",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.4",
|
||||||
"proxy-from-env": "^1.1.0"
|
"proxy-from-env": "^1.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -18761,13 +18764,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/form-data": {
|
"node_modules/form-data": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
||||||
"integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==",
|
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"asynckit": "^0.4.0",
|
"asynckit": "^0.4.0",
|
||||||
"combined-stream": "^1.0.8",
|
"combined-stream": "^1.0.8",
|
||||||
"es-set-tostringtag": "^2.1.0",
|
"es-set-tostringtag": "^2.1.0",
|
||||||
|
"hasown": "^2.0.2",
|
||||||
"mime-types": "^2.1.12"
|
"mime-types": "^2.1.12"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
@@ -181,7 +181,7 @@
|
|||||||
"ajv": "^8.12.0",
|
"ajv": "^8.12.0",
|
||||||
"argon2": "^0.31.2",
|
"argon2": "^0.31.2",
|
||||||
"aws-sdk": "^2.1553.0",
|
"aws-sdk": "^2.1553.0",
|
||||||
"axios": "^1.6.7",
|
"axios": "^1.11.0",
|
||||||
"axios-retry": "^4.0.0",
|
"axios-retry": "^4.0.0",
|
||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"botbuilder": "^4.23.2",
|
"botbuilder": "^4.23.2",
|
||||||
|
11
backend/src/@types/fastify.d.ts
vendored
11
backend/src/@types/fastify.d.ts
vendored
@@ -93,6 +93,7 @@ import { TProjectEnvServiceFactory } from "@app/services/project-env/project-env
|
|||||||
import { TProjectKeyServiceFactory } from "@app/services/project-key/project-key-service";
|
import { TProjectKeyServiceFactory } from "@app/services/project-key/project-key-service";
|
||||||
import { TProjectMembershipServiceFactory } from "@app/services/project-membership/project-membership-service";
|
import { TProjectMembershipServiceFactory } from "@app/services/project-membership/project-membership-service";
|
||||||
import { TProjectRoleServiceFactory } from "@app/services/project-role/project-role-service";
|
import { TProjectRoleServiceFactory } from "@app/services/project-role/project-role-service";
|
||||||
|
import { TReminderServiceFactory } from "@app/services/reminder/reminder-types";
|
||||||
import { TSecretServiceFactory } from "@app/services/secret/secret-service";
|
import { TSecretServiceFactory } from "@app/services/secret/secret-service";
|
||||||
import { TSecretBlindIndexServiceFactory } from "@app/services/secret-blind-index/secret-blind-index-service";
|
import { TSecretBlindIndexServiceFactory } from "@app/services/secret-blind-index/secret-blind-index-service";
|
||||||
import { TSecretFolderServiceFactory } from "@app/services/secret-folder/secret-folder-service";
|
import { TSecretFolderServiceFactory } from "@app/services/secret-folder/secret-folder-service";
|
||||||
@@ -125,6 +126,15 @@ declare module "@fastify/request-context" {
|
|||||||
namespace: string;
|
namespace: string;
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
aws?: {
|
||||||
|
accountId: string;
|
||||||
|
arn: string;
|
||||||
|
userId: string;
|
||||||
|
partition: string;
|
||||||
|
service: string;
|
||||||
|
resourceType: string;
|
||||||
|
resourceName: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
identityPermissionMetadata?: Record<string, unknown>; // filled by permission service
|
identityPermissionMetadata?: Record<string, unknown>; // filled by permission service
|
||||||
assumedPrivilegeDetails?: { requesterId: string; actorId: string; actorType: ActorType; projectId: string };
|
assumedPrivilegeDetails?: { requesterId: string; actorId: string; actorType: ActorType; projectId: string };
|
||||||
@@ -285,6 +295,7 @@ declare module "fastify" {
|
|||||||
secretScanningV2: TSecretScanningV2ServiceFactory;
|
secretScanningV2: TSecretScanningV2ServiceFactory;
|
||||||
internalCertificateAuthority: TInternalCertificateAuthorityServiceFactory;
|
internalCertificateAuthority: TInternalCertificateAuthorityServiceFactory;
|
||||||
pkiTemplate: TPkiTemplatesServiceFactory;
|
pkiTemplate: TPkiTemplatesServiceFactory;
|
||||||
|
reminder: TReminderServiceFactory;
|
||||||
};
|
};
|
||||||
// this is exclusive use for middlewares in which we need to inject data
|
// this is exclusive use for middlewares in which we need to inject data
|
||||||
// everywhere else access using service layer
|
// everywhere else access using service layer
|
||||||
|
33
backend/src/@types/knex.d.ts
vendored
33
backend/src/@types/knex.d.ts
vendored
@@ -489,6 +489,11 @@ import {
|
|||||||
TWorkflowIntegrationsInsert,
|
TWorkflowIntegrationsInsert,
|
||||||
TWorkflowIntegrationsUpdate
|
TWorkflowIntegrationsUpdate
|
||||||
} from "@app/db/schemas";
|
} from "@app/db/schemas";
|
||||||
|
import {
|
||||||
|
TAccessApprovalPoliciesEnvironments,
|
||||||
|
TAccessApprovalPoliciesEnvironmentsInsert,
|
||||||
|
TAccessApprovalPoliciesEnvironmentsUpdate
|
||||||
|
} from "@app/db/schemas/access-approval-policies-environments";
|
||||||
import {
|
import {
|
||||||
TIdentityLdapAuths,
|
TIdentityLdapAuths,
|
||||||
TIdentityLdapAuthsInsert,
|
TIdentityLdapAuthsInsert,
|
||||||
@@ -504,6 +509,17 @@ import {
|
|||||||
TProjectMicrosoftTeamsConfigsInsert,
|
TProjectMicrosoftTeamsConfigsInsert,
|
||||||
TProjectMicrosoftTeamsConfigsUpdate
|
TProjectMicrosoftTeamsConfigsUpdate
|
||||||
} from "@app/db/schemas/project-microsoft-teams-configs";
|
} from "@app/db/schemas/project-microsoft-teams-configs";
|
||||||
|
import { TReminders, TRemindersInsert, TRemindersUpdate } from "@app/db/schemas/reminders";
|
||||||
|
import {
|
||||||
|
TRemindersRecipients,
|
||||||
|
TRemindersRecipientsInsert,
|
||||||
|
TRemindersRecipientsUpdate
|
||||||
|
} from "@app/db/schemas/reminders-recipients";
|
||||||
|
import {
|
||||||
|
TSecretApprovalPoliciesEnvironments,
|
||||||
|
TSecretApprovalPoliciesEnvironmentsInsert,
|
||||||
|
TSecretApprovalPoliciesEnvironmentsUpdate
|
||||||
|
} from "@app/db/schemas/secret-approval-policies-environments";
|
||||||
import {
|
import {
|
||||||
TSecretReminderRecipients,
|
TSecretReminderRecipients,
|
||||||
TSecretReminderRecipientsInsert,
|
TSecretReminderRecipientsInsert,
|
||||||
@@ -881,6 +897,12 @@ declare module "knex/types/tables" {
|
|||||||
TAccessApprovalPoliciesBypassersUpdate
|
TAccessApprovalPoliciesBypassersUpdate
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
[TableName.AccessApprovalPolicyEnvironment]: KnexOriginal.CompositeTableType<
|
||||||
|
TAccessApprovalPoliciesEnvironments,
|
||||||
|
TAccessApprovalPoliciesEnvironmentsInsert,
|
||||||
|
TAccessApprovalPoliciesEnvironmentsUpdate
|
||||||
|
>;
|
||||||
|
|
||||||
[TableName.AccessApprovalRequest]: KnexOriginal.CompositeTableType<
|
[TableName.AccessApprovalRequest]: KnexOriginal.CompositeTableType<
|
||||||
TAccessApprovalRequests,
|
TAccessApprovalRequests,
|
||||||
TAccessApprovalRequestsInsert,
|
TAccessApprovalRequestsInsert,
|
||||||
@@ -929,6 +951,11 @@ declare module "knex/types/tables" {
|
|||||||
TSecretApprovalRequestSecretTagsInsert,
|
TSecretApprovalRequestSecretTagsInsert,
|
||||||
TSecretApprovalRequestSecretTagsUpdate
|
TSecretApprovalRequestSecretTagsUpdate
|
||||||
>;
|
>;
|
||||||
|
[TableName.SecretApprovalPolicyEnvironment]: KnexOriginal.CompositeTableType<
|
||||||
|
TSecretApprovalPoliciesEnvironments,
|
||||||
|
TSecretApprovalPoliciesEnvironmentsInsert,
|
||||||
|
TSecretApprovalPoliciesEnvironmentsUpdate
|
||||||
|
>;
|
||||||
[TableName.SecretRotation]: KnexOriginal.CompositeTableType<
|
[TableName.SecretRotation]: KnexOriginal.CompositeTableType<
|
||||||
TSecretRotations,
|
TSecretRotations,
|
||||||
TSecretRotationsInsert,
|
TSecretRotationsInsert,
|
||||||
@@ -1211,5 +1238,11 @@ declare module "knex/types/tables" {
|
|||||||
TSecretScanningConfigsInsert,
|
TSecretScanningConfigsInsert,
|
||||||
TSecretScanningConfigsUpdate
|
TSecretScanningConfigsUpdate
|
||||||
>;
|
>;
|
||||||
|
[TableName.Reminder]: KnexOriginal.CompositeTableType<TReminders, TRemindersInsert, TRemindersUpdate>;
|
||||||
|
[TableName.ReminderRecipient]: KnexOriginal.CompositeTableType<
|
||||||
|
TRemindersRecipients,
|
||||||
|
TRemindersRecipientsInsert,
|
||||||
|
TRemindersRecipientsUpdate
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,43 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { TableName } from "../schemas";
|
||||||
|
import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils";
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
if (!(await knex.schema.hasTable(TableName.Reminder))) {
|
||||||
|
await knex.schema.createTable(TableName.Reminder, (t) => {
|
||||||
|
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
|
||||||
|
t.uuid("secretId").nullable();
|
||||||
|
t.foreign("secretId").references("id").inTable(TableName.SecretV2).onDelete("CASCADE");
|
||||||
|
t.string("message", 1024).nullable();
|
||||||
|
t.integer("repeatDays").checkPositive().nullable();
|
||||||
|
t.timestamp("nextReminderDate").notNullable();
|
||||||
|
t.timestamps(true, true, true);
|
||||||
|
t.unique("secretId");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(await knex.schema.hasTable(TableName.ReminderRecipient))) {
|
||||||
|
await knex.schema.createTable(TableName.ReminderRecipient, (t) => {
|
||||||
|
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
|
||||||
|
t.uuid("reminderId").notNullable();
|
||||||
|
t.foreign("reminderId").references("id").inTable(TableName.Reminder).onDelete("CASCADE");
|
||||||
|
t.uuid("userId").notNullable();
|
||||||
|
t.foreign("userId").references("id").inTable(TableName.Users).onDelete("CASCADE");
|
||||||
|
t.timestamps(true, true, true);
|
||||||
|
t.index("reminderId");
|
||||||
|
t.index("userId");
|
||||||
|
t.unique(["reminderId", "userId"]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await createOnUpdateTrigger(knex, TableName.Reminder);
|
||||||
|
await createOnUpdateTrigger(knex, TableName.ReminderRecipient);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
await dropOnUpdateTrigger(knex, TableName.Reminder);
|
||||||
|
await dropOnUpdateTrigger(knex, TableName.ReminderRecipient);
|
||||||
|
await knex.schema.dropTableIfExists(TableName.ReminderRecipient);
|
||||||
|
await knex.schema.dropTableIfExists(TableName.Reminder);
|
||||||
|
}
|
@@ -0,0 +1,19 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { TableName } from "../schemas";
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
if (!(await knex.schema.hasColumn(TableName.AppConnection, "gatewayId"))) {
|
||||||
|
await knex.schema.alterTable(TableName.AppConnection, (t) => {
|
||||||
|
t.uuid("gatewayId").nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
if (await knex.schema.hasColumn(TableName.AppConnection, "gatewayId")) {
|
||||||
|
await knex.schema.alterTable(TableName.AppConnection, (t) => {
|
||||||
|
t.dropColumn("gatewayId");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
432
backend/src/db/migrations/20250718133527_project-unify-revert.ts
Normal file
432
backend/src/db/migrations/20250718133527_project-unify-revert.ts
Normal file
@@ -0,0 +1,432 @@
|
|||||||
|
import slugify from "@sindresorhus/slugify";
|
||||||
|
import { Knex } from "knex";
|
||||||
|
import { v4 as uuidV4 } from "uuid";
|
||||||
|
|
||||||
|
import { alphaNumericNanoId } from "@app/lib/nanoid";
|
||||||
|
|
||||||
|
import { ProjectType, TableName } from "../schemas";
|
||||||
|
|
||||||
|
/* eslint-disable no-await-in-loop,@typescript-eslint/ban-ts-comment */
|
||||||
|
|
||||||
|
// Single query to get all projects that need any kind of kickout
|
||||||
|
const getProjectsNeedingKickouts = async (
|
||||||
|
knex: Knex
|
||||||
|
): Promise<
|
||||||
|
Array<{
|
||||||
|
id: string;
|
||||||
|
defaultProduct: string;
|
||||||
|
needsSecretManager: boolean;
|
||||||
|
needsCertManager: boolean;
|
||||||
|
needsSecretScanning: boolean;
|
||||||
|
needsKms: boolean;
|
||||||
|
needsSsh: boolean;
|
||||||
|
}>
|
||||||
|
> => {
|
||||||
|
const result = await knex.raw(
|
||||||
|
`
|
||||||
|
SELECT DISTINCT
|
||||||
|
p.id,
|
||||||
|
p."defaultProduct",
|
||||||
|
|
||||||
|
-- Use CASE with direct joins instead of EXISTS subqueries
|
||||||
|
CASE WHEN p."defaultProduct" != 'secret-manager' AND s.secret_exists IS NOT NULL THEN true ELSE false END AS "needsSecretManager",
|
||||||
|
CASE WHEN p."defaultProduct" != 'cert-manager' AND ca.ca_exists IS NOT NULL THEN true ELSE false END AS "needsCertManager",
|
||||||
|
CASE WHEN p."defaultProduct" != 'secret-scanning' AND ssds.ssds_exists IS NOT NULL THEN true ELSE false END AS "needsSecretScanning",
|
||||||
|
CASE WHEN p."defaultProduct" != 'kms' AND kk.kms_exists IS NOT NULL THEN true ELSE false END AS "needsKms",
|
||||||
|
CASE WHEN p."defaultProduct" != 'ssh' AND sc.ssh_exists IS NOT NULL THEN true ELSE false END AS "needsSsh"
|
||||||
|
|
||||||
|
FROM projects p
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT DISTINCT e."projectId", 1 as secret_exists
|
||||||
|
FROM secrets_v2 s
|
||||||
|
JOIN secret_folders sf ON sf.id = s."folderId"
|
||||||
|
JOIN project_environments e ON e.id = sf."envId"
|
||||||
|
) s ON s."projectId" = p.id AND p."defaultProduct" != 'secret-manager'
|
||||||
|
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT DISTINCT "projectId", 1 as ca_exists
|
||||||
|
FROM certificate_authorities
|
||||||
|
) ca ON ca."projectId" = p.id AND p."defaultProduct" != 'cert-manager'
|
||||||
|
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT DISTINCT "projectId", 1 as ssds_exists
|
||||||
|
FROM secret_scanning_data_sources
|
||||||
|
) ssds ON ssds."projectId" = p.id AND p."defaultProduct" != 'secret-scanning'
|
||||||
|
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT DISTINCT "projectId", 1 as kms_exists
|
||||||
|
FROM kms_keys
|
||||||
|
WHERE "isReserved" = false
|
||||||
|
) kk ON kk."projectId" = p.id AND p."defaultProduct" != 'kms'
|
||||||
|
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT DISTINCT sca."projectId", 1 as ssh_exists
|
||||||
|
FROM ssh_certificates sc
|
||||||
|
JOIN ssh_certificate_authorities sca ON sca.id = sc."sshCaId"
|
||||||
|
) sc ON sc."projectId" = p.id AND p."defaultProduct" != 'ssh'
|
||||||
|
|
||||||
|
WHERE p."defaultProduct" IS NOT NULL
|
||||||
|
AND (
|
||||||
|
(p."defaultProduct" != 'secret-manager' AND s.secret_exists IS NOT NULL) OR
|
||||||
|
(p."defaultProduct" != 'cert-manager' AND ca.ca_exists IS NOT NULL) OR
|
||||||
|
(p."defaultProduct" != 'secret-scanning' AND ssds.ssds_exists IS NOT NULL) OR
|
||||||
|
(p."defaultProduct" != 'kms' AND kk.kms_exists IS NOT NULL) OR
|
||||||
|
(p."defaultProduct" != 'ssh' AND sc.ssh_exists IS NOT NULL)
|
||||||
|
)
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
return result.rows;
|
||||||
|
};
|
||||||
|
|
||||||
|
const newProject = async (knex: Knex, projectId: string, projectType: ProjectType) => {
|
||||||
|
const newProjectId = uuidV4();
|
||||||
|
const project = await knex(TableName.Project).where("id", projectId).first();
|
||||||
|
await knex(TableName.Project).insert({
|
||||||
|
...project,
|
||||||
|
type: projectType,
|
||||||
|
defaultProduct: null,
|
||||||
|
// @ts-ignore id is required
|
||||||
|
id: newProjectId,
|
||||||
|
slug: slugify(`${project?.name}-${alphaNumericNanoId(8)}`)
|
||||||
|
});
|
||||||
|
|
||||||
|
const customRoleMapping: Record<string, string> = {};
|
||||||
|
const projectCustomRoles = await knex(TableName.ProjectRoles).where("projectId", projectId);
|
||||||
|
if (projectCustomRoles.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.ProjectRoles,
|
||||||
|
projectCustomRoles.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
customRoleMapping[el.id] = id;
|
||||||
|
return {
|
||||||
|
...el,
|
||||||
|
id,
|
||||||
|
projectId: newProjectId,
|
||||||
|
permissions: el.permissions ? JSON.stringify(el.permissions) : el.permissions
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const groupMembershipMapping: Record<string, string> = {};
|
||||||
|
const groupMemberships = await knex(TableName.GroupProjectMembership).where("projectId", projectId);
|
||||||
|
if (groupMemberships.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.GroupProjectMembership,
|
||||||
|
groupMemberships.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
groupMembershipMapping[el.id] = id;
|
||||||
|
return { ...el, id, projectId: newProjectId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupMembershipRoles = await knex(TableName.GroupProjectMembershipRole).whereIn(
|
||||||
|
"projectMembershipId",
|
||||||
|
groupMemberships.map((el) => el.id)
|
||||||
|
);
|
||||||
|
if (groupMembershipRoles.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.GroupProjectMembershipRole,
|
||||||
|
groupMembershipRoles.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
const projectMembershipId = groupMembershipMapping[el.projectMembershipId];
|
||||||
|
const customRoleId = el.customRoleId ? customRoleMapping[el.customRoleId] : el.customRoleId;
|
||||||
|
return { ...el, id, projectMembershipId, customRoleId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const identityProjectMembershipMapping: Record<string, string> = {};
|
||||||
|
const identities = await knex(TableName.IdentityProjectMembership).where("projectId", projectId);
|
||||||
|
if (identities.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.IdentityProjectMembership,
|
||||||
|
identities.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
identityProjectMembershipMapping[el.id] = id;
|
||||||
|
return { ...el, id, projectId: newProjectId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const identitiesRoles = await knex(TableName.IdentityProjectMembershipRole).whereIn(
|
||||||
|
"projectMembershipId",
|
||||||
|
identities.map((el) => el.id)
|
||||||
|
);
|
||||||
|
if (identitiesRoles.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.IdentityProjectMembershipRole,
|
||||||
|
identitiesRoles.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
const projectMembershipId = identityProjectMembershipMapping[el.projectMembershipId];
|
||||||
|
const customRoleId = el.customRoleId ? customRoleMapping[el.customRoleId] : el.customRoleId;
|
||||||
|
return { ...el, id, projectMembershipId, customRoleId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectMembershipMapping: Record<string, string> = {};
|
||||||
|
const projectUserMembers = await knex(TableName.ProjectMembership).where("projectId", projectId);
|
||||||
|
if (projectUserMembers.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.ProjectMembership,
|
||||||
|
projectUserMembers.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
projectMembershipMapping[el.id] = id;
|
||||||
|
return { ...el, id, projectId: newProjectId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const membershipRoles = await knex(TableName.ProjectUserMembershipRole).whereIn(
|
||||||
|
"projectMembershipId",
|
||||||
|
projectUserMembers.map((el) => el.id)
|
||||||
|
);
|
||||||
|
if (membershipRoles.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.ProjectUserMembershipRole,
|
||||||
|
membershipRoles.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
const projectMembershipId = projectMembershipMapping[el.projectMembershipId];
|
||||||
|
const customRoleId = el.customRoleId ? customRoleMapping[el.customRoleId] : el.customRoleId;
|
||||||
|
return { ...el, id, projectMembershipId, customRoleId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const kmsKeys = await knex(TableName.KmsKey).where("projectId", projectId).andWhere("isReserved", true);
|
||||||
|
if (kmsKeys.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.KmsKey,
|
||||||
|
kmsKeys.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
const slug = slugify(alphaNumericNanoId(8).toLowerCase());
|
||||||
|
return { ...el, id, slug, projectId: newProjectId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectBot = await knex(TableName.ProjectBot).where("projectId", projectId).first();
|
||||||
|
if (projectBot) {
|
||||||
|
const newProjectBot = { ...projectBot, id: uuidV4(), projectId: newProjectId };
|
||||||
|
await knex(TableName.ProjectBot).insert(newProjectBot);
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectKeys = await knex(TableName.ProjectKeys).where("projectId", projectId);
|
||||||
|
if (projectKeys.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.ProjectKeys,
|
||||||
|
projectKeys.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
return { ...el, id, projectId: newProjectId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectGateways = await knex(TableName.ProjectGateway).where("projectId", projectId);
|
||||||
|
if (projectGateways.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.ProjectGateway,
|
||||||
|
projectGateways.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
return { ...el, id, projectId: newProjectId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectSlackConfigs = await knex(TableName.ProjectSlackConfigs).where("projectId", projectId);
|
||||||
|
if (projectSlackConfigs.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.ProjectSlackConfigs,
|
||||||
|
projectSlackConfigs.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
return { ...el, id, projectId: newProjectId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectMicrosoftTeamsConfigs = await knex(TableName.ProjectMicrosoftTeamsConfigs).where("projectId", projectId);
|
||||||
|
if (projectMicrosoftTeamsConfigs.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.ProjectMicrosoftTeamsConfigs,
|
||||||
|
projectMicrosoftTeamsConfigs.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
return { ...el, id, projectId: newProjectId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const trustedIps = await knex(TableName.TrustedIps).where("projectId", projectId);
|
||||||
|
if (trustedIps.length) {
|
||||||
|
await knex.batchInsert(
|
||||||
|
TableName.TrustedIps,
|
||||||
|
trustedIps.map((el) => {
|
||||||
|
const id = uuidV4();
|
||||||
|
return { ...el, id, projectId: newProjectId };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newProjectId;
|
||||||
|
};
|
||||||
|
|
||||||
|
const kickOutSecretManagerProject = async (knex: Knex, oldProjectId: string) => {
|
||||||
|
const newProjectId = await newProject(knex, oldProjectId, ProjectType.SecretManager);
|
||||||
|
await knex(TableName.IntegrationAuth).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.Environment).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.SecretBlindIndex).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.SecretSync).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.SecretTag).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.SecretReminderRecipients).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.ServiceToken).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const kickOutCertManagerProject = async (knex: Knex, oldProjectId: string) => {
|
||||||
|
const newProjectId = await newProject(knex, oldProjectId, ProjectType.CertificateManager);
|
||||||
|
await knex(TableName.CertificateAuthority).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.Certificate).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.PkiSubscriber).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.PkiCollection).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.PkiAlert).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const kickOutSecretScanningProject = async (knex: Knex, oldProjectId: string) => {
|
||||||
|
const newProjectId = await newProject(knex, oldProjectId, ProjectType.SecretScanning);
|
||||||
|
await knex(TableName.SecretScanningConfig).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.SecretScanningDataSource).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.SecretScanningFinding).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const kickOutKmsProject = async (knex: Knex, oldProjectId: string) => {
|
||||||
|
const newProjectId = await newProject(knex, oldProjectId, ProjectType.KMS);
|
||||||
|
await knex(TableName.KmsKey)
|
||||||
|
.where("projectId", oldProjectId)
|
||||||
|
.andWhere("isReserved", false)
|
||||||
|
.update("projectId", newProjectId);
|
||||||
|
await knex(TableName.KmipClient).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const kickOutSshProject = async (knex: Knex, oldProjectId: string) => {
|
||||||
|
const newProjectId = await newProject(knex, oldProjectId, ProjectType.SSH);
|
||||||
|
await knex(TableName.SshHost).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.ProjectSshConfig).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.SshCertificateAuthority).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
await knex(TableName.SshHostGroup).where("projectId", oldProjectId).update("projectId", newProjectId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const BATCH_SIZE = 1000;
|
||||||
|
const MIGRATION_TIMEOUT = 30 * 60 * 1000; // 30 minutes
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
const result = await knex.raw("SHOW statement_timeout");
|
||||||
|
const originalTimeout = result.rows[0].statement_timeout;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await knex.raw(`SET statement_timeout = ${MIGRATION_TIMEOUT}`);
|
||||||
|
|
||||||
|
const hasTemplateTypeColumn = await knex.schema.hasColumn(TableName.ProjectTemplates, "type");
|
||||||
|
if (hasTemplateTypeColumn) {
|
||||||
|
await knex(TableName.ProjectTemplates).whereNull("type").update({
|
||||||
|
type: ProjectType.SecretManager
|
||||||
|
});
|
||||||
|
await knex.schema.alterTable(TableName.ProjectTemplates, (t) => {
|
||||||
|
t.string("type").notNullable().defaultTo(ProjectType.SecretManager).alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasTypeColumn = await knex.schema.hasColumn(TableName.Project, "type");
|
||||||
|
const hasDefaultTypeColumn = await knex.schema.hasColumn(TableName.Project, "defaultProduct");
|
||||||
|
if (hasTypeColumn && hasDefaultTypeColumn) {
|
||||||
|
await knex(TableName.Project).update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore this is because this field is created later
|
||||||
|
type: knex.raw(`"defaultProduct"`)
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.Project, (t) => {
|
||||||
|
t.string("type").notNullable().alter();
|
||||||
|
t.string("defaultProduct").nullable().alter();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get all projects that need kickouts in a single query
|
||||||
|
const projectsNeedingKickouts = await getProjectsNeedingKickouts(knex);
|
||||||
|
|
||||||
|
// Process projects in batches to avoid overwhelming the database
|
||||||
|
for (let i = 0; i < projectsNeedingKickouts.length; i += projectsNeedingKickouts.length) {
|
||||||
|
const batch = projectsNeedingKickouts.slice(i, i + BATCH_SIZE);
|
||||||
|
const processedIds: string[] = [];
|
||||||
|
|
||||||
|
for (const project of batch) {
|
||||||
|
const kickoutPromises: Promise<void>[] = [];
|
||||||
|
|
||||||
|
// Only add kickouts that are actually needed (flags are pre-computed)
|
||||||
|
if (project.needsSecretManager) {
|
||||||
|
kickoutPromises.push(kickOutSecretManagerProject(knex, project.id));
|
||||||
|
}
|
||||||
|
if (project.needsCertManager) {
|
||||||
|
kickoutPromises.push(kickOutCertManagerProject(knex, project.id));
|
||||||
|
}
|
||||||
|
if (project.needsKms) {
|
||||||
|
kickoutPromises.push(kickOutKmsProject(knex, project.id));
|
||||||
|
}
|
||||||
|
if (project.needsSsh) {
|
||||||
|
kickoutPromises.push(kickOutSshProject(knex, project.id));
|
||||||
|
}
|
||||||
|
if (project.needsSecretScanning) {
|
||||||
|
kickoutPromises.push(kickOutSecretScanningProject(knex, project.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute all kickouts in parallel and handle any failures gracefully
|
||||||
|
if (kickoutPromises.length > 0) {
|
||||||
|
const results = await Promise.allSettled(kickoutPromises);
|
||||||
|
|
||||||
|
// Log any failures for debugging
|
||||||
|
results.forEach((res) => {
|
||||||
|
if (res.status === "rejected") {
|
||||||
|
throw new Error(`Migration failed for project ${project.id}: ${res.reason}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
processedIds.push(project.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear defaultProduct for the processed batch
|
||||||
|
if (processedIds.length > 0) {
|
||||||
|
await knex(TableName.Project).whereIn("id", processedIds).update("defaultProduct", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
await knex.raw(`SET statement_timeout = '${originalTimeout}'`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
const hasTypeColumn = await knex.schema.hasColumn(TableName.Project, "type");
|
||||||
|
const hasDefaultTypeColumn = await knex.schema.hasColumn(TableName.Project, "defaultProduct");
|
||||||
|
if (hasTypeColumn && hasDefaultTypeColumn) {
|
||||||
|
await knex(TableName.Project).update({
|
||||||
|
// eslint-disable-next-line
|
||||||
|
// @ts-ignore this is because this field is created later
|
||||||
|
defaultProduct: knex.raw(`
|
||||||
|
CASE
|
||||||
|
WHEN "type" IS NULL OR "type" = '' THEN 'secret-manager'
|
||||||
|
ELSE "type"
|
||||||
|
END
|
||||||
|
`)
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.Project, (t) => {
|
||||||
|
t.string("type").nullable().alter();
|
||||||
|
t.string("defaultProduct").notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasTemplateTypeColumn = await knex.schema.hasColumn(TableName.ProjectTemplates, "type");
|
||||||
|
if (hasTemplateTypeColumn) {
|
||||||
|
await knex.schema.alterTable(TableName.ProjectTemplates, (t) => {
|
||||||
|
t.string("type").nullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,21 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { TableName } from "../schemas";
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
const hasColumn = await knex.schema.hasColumn(TableName.IdentityAwsAuth, "allowedPrincipalArns");
|
||||||
|
if (hasColumn) {
|
||||||
|
await knex.schema.alterTable(TableName.IdentityAwsAuth, (t) => {
|
||||||
|
t.string("allowedPrincipalArns", 4096).notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
const hasColumn = await knex.schema.hasColumn(TableName.IdentityAwsAuth, "allowedPrincipalArns");
|
||||||
|
if (hasColumn) {
|
||||||
|
await knex.schema.alterTable(TableName.IdentityAwsAuth, (t) => {
|
||||||
|
t.string("allowedPrincipalArns", 2048).notNullable().alter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,96 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { selectAllTableCols } from "@app/lib/knex";
|
||||||
|
|
||||||
|
import { TableName } from "../schemas";
|
||||||
|
import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils";
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
if (!(await knex.schema.hasTable(TableName.AccessApprovalPolicyEnvironment))) {
|
||||||
|
await knex.schema.createTable(TableName.AccessApprovalPolicyEnvironment, (t) => {
|
||||||
|
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
|
||||||
|
t.uuid("policyId").notNullable();
|
||||||
|
t.foreign("policyId").references("id").inTable(TableName.AccessApprovalPolicy).onDelete("CASCADE");
|
||||||
|
t.uuid("envId").notNullable();
|
||||||
|
t.foreign("envId").references("id").inTable(TableName.Environment);
|
||||||
|
t.timestamps(true, true, true);
|
||||||
|
t.unique(["policyId", "envId"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
await createOnUpdateTrigger(knex, TableName.AccessApprovalPolicyEnvironment);
|
||||||
|
|
||||||
|
const existingAccessApprovalPolicies = await knex(TableName.AccessApprovalPolicy)
|
||||||
|
.select(selectAllTableCols(TableName.AccessApprovalPolicy))
|
||||||
|
.whereNotNull(`${TableName.AccessApprovalPolicy}.envId`);
|
||||||
|
|
||||||
|
const accessApprovalPolicies = existingAccessApprovalPolicies.map(async (policy) => {
|
||||||
|
await knex(TableName.AccessApprovalPolicyEnvironment).insert({
|
||||||
|
policyId: policy.id,
|
||||||
|
envId: policy.envId
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(accessApprovalPolicies);
|
||||||
|
}
|
||||||
|
if (!(await knex.schema.hasTable(TableName.SecretApprovalPolicyEnvironment))) {
|
||||||
|
await knex.schema.createTable(TableName.SecretApprovalPolicyEnvironment, (t) => {
|
||||||
|
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
|
||||||
|
t.uuid("policyId").notNullable();
|
||||||
|
t.foreign("policyId").references("id").inTable(TableName.SecretApprovalPolicy).onDelete("CASCADE");
|
||||||
|
t.uuid("envId").notNullable();
|
||||||
|
t.foreign("envId").references("id").inTable(TableName.Environment);
|
||||||
|
t.timestamps(true, true, true);
|
||||||
|
t.unique(["policyId", "envId"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
await createOnUpdateTrigger(knex, TableName.SecretApprovalPolicyEnvironment);
|
||||||
|
|
||||||
|
const existingSecretApprovalPolicies = await knex(TableName.SecretApprovalPolicy)
|
||||||
|
.select(selectAllTableCols(TableName.SecretApprovalPolicy))
|
||||||
|
.whereNotNull(`${TableName.SecretApprovalPolicy}.envId`);
|
||||||
|
|
||||||
|
const secretApprovalPolicies = existingSecretApprovalPolicies.map(async (policy) => {
|
||||||
|
await knex(TableName.SecretApprovalPolicyEnvironment).insert({
|
||||||
|
policyId: policy.id,
|
||||||
|
envId: policy.envId
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(secretApprovalPolicies);
|
||||||
|
}
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalPolicy, (t) => {
|
||||||
|
t.dropForeign(["envId"]);
|
||||||
|
|
||||||
|
// Add the new foreign key constraint with ON DELETE SET NULL
|
||||||
|
t.foreign("envId").references("id").inTable(TableName.Environment).onDelete("SET NULL");
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.SecretApprovalPolicy, (t) => {
|
||||||
|
t.dropForeign(["envId"]);
|
||||||
|
|
||||||
|
// Add the new foreign key constraint with ON DELETE SET NULL
|
||||||
|
t.foreign("envId").references("id").inTable(TableName.Environment).onDelete("SET NULL");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
if (await knex.schema.hasTable(TableName.AccessApprovalPolicyEnvironment)) {
|
||||||
|
await knex.schema.dropTableIfExists(TableName.AccessApprovalPolicyEnvironment);
|
||||||
|
await dropOnUpdateTrigger(knex, TableName.AccessApprovalPolicyEnvironment);
|
||||||
|
}
|
||||||
|
if (await knex.schema.hasTable(TableName.SecretApprovalPolicyEnvironment)) {
|
||||||
|
await knex.schema.dropTableIfExists(TableName.SecretApprovalPolicyEnvironment);
|
||||||
|
await dropOnUpdateTrigger(knex, TableName.SecretApprovalPolicyEnvironment);
|
||||||
|
}
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.AccessApprovalPolicy, (t) => {
|
||||||
|
t.dropForeign(["envId"]);
|
||||||
|
t.foreign("envId").references("id").inTable(TableName.Environment).onDelete("CASCADE");
|
||||||
|
});
|
||||||
|
|
||||||
|
await knex.schema.alterTable(TableName.SecretApprovalPolicy, (t) => {
|
||||||
|
t.dropForeign(["envId"]);
|
||||||
|
t.foreign("envId").references("id").inTable(TableName.Environment).onDelete("CASCADE");
|
||||||
|
});
|
||||||
|
}
|
@@ -0,0 +1,111 @@
|
|||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { chunkArray } from "@app/lib/fn";
|
||||||
|
import { logger } from "@app/lib/logger";
|
||||||
|
|
||||||
|
import { TableName } from "../schemas";
|
||||||
|
import { TReminders, TRemindersInsert } from "../schemas/reminders";
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
logger.info("Initializing secret reminders migration");
|
||||||
|
const hasReminderTable = await knex.schema.hasTable(TableName.Reminder);
|
||||||
|
|
||||||
|
if (hasReminderTable) {
|
||||||
|
const secretsWithLatestVersions = await knex(TableName.SecretV2)
|
||||||
|
.whereNotNull(`${TableName.SecretV2}.reminderRepeatDays`)
|
||||||
|
.whereRaw(`"${TableName.SecretV2}"."reminderRepeatDays" > 0`)
|
||||||
|
.innerJoin(TableName.SecretVersionV2, (qb) => {
|
||||||
|
void qb
|
||||||
|
.on(`${TableName.SecretVersionV2}.secretId`, "=", `${TableName.SecretV2}.id`)
|
||||||
|
.andOn(`${TableName.SecretVersionV2}.reminderRepeatDays`, "=", `${TableName.SecretV2}.reminderRepeatDays`);
|
||||||
|
})
|
||||||
|
.whereIn([`${TableName.SecretVersionV2}.secretId`, `${TableName.SecretVersionV2}.version`], (qb) => {
|
||||||
|
void qb
|
||||||
|
.select(["v2.secretId", knex.raw("MIN(v2.version) as version")])
|
||||||
|
.from(`${TableName.SecretVersionV2} as v2`)
|
||||||
|
.innerJoin(`${TableName.SecretV2} as s2`, "v2.secretId", "s2.id")
|
||||||
|
.whereRaw(`v2."reminderRepeatDays" = s2."reminderRepeatDays"`)
|
||||||
|
.whereNotNull("v2.reminderRepeatDays")
|
||||||
|
.whereRaw(`v2."reminderRepeatDays" > 0`)
|
||||||
|
.groupBy("v2.secretId");
|
||||||
|
})
|
||||||
|
// Add LEFT JOIN with Reminder table to check for existing reminders
|
||||||
|
.leftJoin(TableName.Reminder, `${TableName.Reminder}.secretId`, `${TableName.SecretV2}.id`)
|
||||||
|
// Only include secrets that don't already have reminders
|
||||||
|
.whereNull(`${TableName.Reminder}.secretId`)
|
||||||
|
.select(
|
||||||
|
knex.ref("id").withSchema(TableName.SecretV2).as("secretId"),
|
||||||
|
knex.ref("reminderRepeatDays").withSchema(TableName.SecretV2).as("reminderRepeatDays"),
|
||||||
|
knex.ref("reminderNote").withSchema(TableName.SecretV2).as("reminderNote"),
|
||||||
|
knex.ref("createdAt").withSchema(TableName.SecretVersionV2).as("createdAt")
|
||||||
|
);
|
||||||
|
|
||||||
|
logger.info(`Found ${secretsWithLatestVersions.length} reminders to migrate`);
|
||||||
|
|
||||||
|
const reminderInserts: TRemindersInsert[] = [];
|
||||||
|
if (secretsWithLatestVersions.length > 0) {
|
||||||
|
secretsWithLatestVersions.forEach((secret) => {
|
||||||
|
if (!secret.reminderRepeatDays) return;
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
const createdAt = new Date(secret.createdAt);
|
||||||
|
let nextReminderDate = new Date(createdAt);
|
||||||
|
nextReminderDate.setDate(nextReminderDate.getDate() + secret.reminderRepeatDays);
|
||||||
|
|
||||||
|
// If the next reminder date is in the past, calculate the proper next occurrence
|
||||||
|
if (nextReminderDate < now) {
|
||||||
|
const daysSinceCreation = Math.floor((now.getTime() - createdAt.getTime()) / (1000 * 60 * 60 * 24));
|
||||||
|
const daysIntoCurrentCycle = daysSinceCreation % secret.reminderRepeatDays;
|
||||||
|
const daysUntilNextReminder = secret.reminderRepeatDays - daysIntoCurrentCycle;
|
||||||
|
|
||||||
|
nextReminderDate = new Date(now);
|
||||||
|
nextReminderDate.setDate(now.getDate() + daysUntilNextReminder);
|
||||||
|
}
|
||||||
|
|
||||||
|
reminderInserts.push({
|
||||||
|
secretId: secret.secretId,
|
||||||
|
message: secret.reminderNote,
|
||||||
|
repeatDays: secret.reminderRepeatDays,
|
||||||
|
nextReminderDate
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const commitBatches = chunkArray(reminderInserts, 2000);
|
||||||
|
for (const commitBatch of commitBatches) {
|
||||||
|
const insertedReminders = (await knex
|
||||||
|
.batchInsert(TableName.Reminder, commitBatch)
|
||||||
|
.returning("*")) as TReminders[];
|
||||||
|
|
||||||
|
const insertedReminderSecretIds = insertedReminders.map((reminder) => reminder.secretId).filter(Boolean);
|
||||||
|
|
||||||
|
const recipients = await knex(TableName.SecretReminderRecipients)
|
||||||
|
.whereRaw(`??.?? IN (${insertedReminderSecretIds.map(() => "?").join(",")})`, [
|
||||||
|
TableName.SecretReminderRecipients,
|
||||||
|
"secretId",
|
||||||
|
...insertedReminderSecretIds
|
||||||
|
])
|
||||||
|
.select(
|
||||||
|
knex.ref("userId").withSchema(TableName.SecretReminderRecipients).as("userId"),
|
||||||
|
knex.ref("secretId").withSchema(TableName.SecretReminderRecipients).as("secretId")
|
||||||
|
);
|
||||||
|
const reminderRecipients = recipients.map((recipient) => ({
|
||||||
|
reminderId: insertedReminders.find((reminder) => reminder.secretId === recipient.secretId)?.id,
|
||||||
|
userId: recipient.userId
|
||||||
|
}));
|
||||||
|
|
||||||
|
const filteredRecipients = reminderRecipients.filter((recipient) => Boolean(recipient.reminderId));
|
||||||
|
await knex.batchInsert(TableName.ReminderRecipient, filteredRecipients);
|
||||||
|
}
|
||||||
|
logger.info(`Successfully migrated ${reminderInserts.length} secret reminders`);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Secret reminders migration completed");
|
||||||
|
} else {
|
||||||
|
logger.warn("Reminder table does not exist, skipping migration");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(): Promise<void> {
|
||||||
|
logger.info("Rollback not implemented for secret reminders fix migration");
|
||||||
|
}
|
@@ -0,0 +1,19 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { TableName } from "../schemas";
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
if (!(await knex.schema.hasColumn(TableName.Project, "secretDetectionIgnoreValues"))) {
|
||||||
|
await knex.schema.alterTable(TableName.Project, (t) => {
|
||||||
|
t.specificType("secretDetectionIgnoreValues", "text[]");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
if (await knex.schema.hasColumn(TableName.Project, "secretDetectionIgnoreValues")) {
|
||||||
|
await knex.schema.alterTable(TableName.Project, (t) => {
|
||||||
|
t.dropColumn("secretDetectionIgnoreValues");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -53,7 +53,7 @@ export const getMigrationEnvConfig = async (superAdminDAL: TSuperAdminDALFactory
|
|||||||
|
|
||||||
let envCfg = Object.freeze(parsedEnv.data);
|
let envCfg = Object.freeze(parsedEnv.data);
|
||||||
|
|
||||||
const fipsEnabled = await crypto.initialize(superAdminDAL);
|
const fipsEnabled = await crypto.initialize(superAdminDAL, envCfg);
|
||||||
|
|
||||||
// Fix for 128-bit entropy encryption key expansion issue:
|
// Fix for 128-bit entropy encryption key expansion issue:
|
||||||
// In FIPS it is not ideal to expand a 128-bit key into 256-bit. We solved this issue in the past by creating the ROOT_ENCRYPTION_KEY.
|
// In FIPS it is not ideal to expand a 128-bit key into 256-bit. We solved this issue in the past by creating the ROOT_ENCRYPTION_KEY.
|
||||||
|
@@ -0,0 +1,25 @@
|
|||||||
|
// Code generated by automation script, DO NOT EDIT.
|
||||||
|
// Automated by pulling database and generating zod schema
|
||||||
|
// To update. Just run npm run generate:schema
|
||||||
|
// Written by akhilmhdh.
|
||||||
|
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
|
export const AccessApprovalPoliciesEnvironmentsSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
policyId: z.string().uuid(),
|
||||||
|
envId: z.string().uuid(),
|
||||||
|
createdAt: z.date(),
|
||||||
|
updatedAt: z.date()
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TAccessApprovalPoliciesEnvironments = z.infer<typeof AccessApprovalPoliciesEnvironmentsSchema>;
|
||||||
|
export type TAccessApprovalPoliciesEnvironmentsInsert = Omit<
|
||||||
|
z.input<typeof AccessApprovalPoliciesEnvironmentsSchema>,
|
||||||
|
TImmutableDBKeys
|
||||||
|
>;
|
||||||
|
export type TAccessApprovalPoliciesEnvironmentsUpdate = Partial<
|
||||||
|
Omit<z.input<typeof AccessApprovalPoliciesEnvironmentsSchema>, TImmutableDBKeys>
|
||||||
|
>;
|
@@ -20,7 +20,8 @@ export const AppConnectionsSchema = z.object({
|
|||||||
orgId: z.string().uuid(),
|
orgId: z.string().uuid(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date(),
|
||||||
isPlatformManagedCredentials: z.boolean().default(false).nullable().optional()
|
isPlatformManagedCredentials: z.boolean().default(false).nullable().optional(),
|
||||||
|
gatewayId: z.string().uuid().nullable().optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TAppConnections = z.infer<typeof AppConnectionsSchema>;
|
export type TAppConnections = z.infer<typeof AppConnectionsSchema>;
|
||||||
|
@@ -100,6 +100,7 @@ export enum TableName {
|
|||||||
AccessApprovalPolicyBypasser = "access_approval_policies_bypassers",
|
AccessApprovalPolicyBypasser = "access_approval_policies_bypassers",
|
||||||
AccessApprovalRequest = "access_approval_requests",
|
AccessApprovalRequest = "access_approval_requests",
|
||||||
AccessApprovalRequestReviewer = "access_approval_requests_reviewers",
|
AccessApprovalRequestReviewer = "access_approval_requests_reviewers",
|
||||||
|
AccessApprovalPolicyEnvironment = "access_approval_policies_environments",
|
||||||
SecretApprovalPolicy = "secret_approval_policies",
|
SecretApprovalPolicy = "secret_approval_policies",
|
||||||
SecretApprovalPolicyApprover = "secret_approval_policies_approvers",
|
SecretApprovalPolicyApprover = "secret_approval_policies_approvers",
|
||||||
SecretApprovalPolicyBypasser = "secret_approval_policies_bypassers",
|
SecretApprovalPolicyBypasser = "secret_approval_policies_bypassers",
|
||||||
@@ -107,6 +108,7 @@ export enum TableName {
|
|||||||
SecretApprovalRequestReviewer = "secret_approval_requests_reviewers",
|
SecretApprovalRequestReviewer = "secret_approval_requests_reviewers",
|
||||||
SecretApprovalRequestSecret = "secret_approval_requests_secrets",
|
SecretApprovalRequestSecret = "secret_approval_requests_secrets",
|
||||||
SecretApprovalRequestSecretTag = "secret_approval_request_secret_tags",
|
SecretApprovalRequestSecretTag = "secret_approval_request_secret_tags",
|
||||||
|
SecretApprovalPolicyEnvironment = "secret_approval_policies_environments",
|
||||||
SecretRotation = "secret_rotations",
|
SecretRotation = "secret_rotations",
|
||||||
SecretRotationOutput = "secret_rotation_outputs",
|
SecretRotationOutput = "secret_rotation_outputs",
|
||||||
SamlConfig = "saml_configs",
|
SamlConfig = "saml_configs",
|
||||||
@@ -160,7 +162,7 @@ export enum TableName {
|
|||||||
SecretRotationV2SecretMapping = "secret_rotation_v2_secret_mappings",
|
SecretRotationV2SecretMapping = "secret_rotation_v2_secret_mappings",
|
||||||
MicrosoftTeamsIntegrations = "microsoft_teams_integrations",
|
MicrosoftTeamsIntegrations = "microsoft_teams_integrations",
|
||||||
ProjectMicrosoftTeamsConfigs = "project_microsoft_teams_configs",
|
ProjectMicrosoftTeamsConfigs = "project_microsoft_teams_configs",
|
||||||
SecretReminderRecipients = "secret_reminder_recipients",
|
SecretReminderRecipients = "secret_reminder_recipients", // TODO(Carlos): Remove this in the future after migrating to the new reminder recipients table
|
||||||
GithubOrgSyncConfig = "github_org_sync_configs",
|
GithubOrgSyncConfig = "github_org_sync_configs",
|
||||||
FolderCommit = "folder_commits",
|
FolderCommit = "folder_commits",
|
||||||
FolderCommitChanges = "folder_commit_changes",
|
FolderCommitChanges = "folder_commit_changes",
|
||||||
@@ -172,7 +174,10 @@ export enum TableName {
|
|||||||
SecretScanningResource = "secret_scanning_resources",
|
SecretScanningResource = "secret_scanning_resources",
|
||||||
SecretScanningScan = "secret_scanning_scans",
|
SecretScanningScan = "secret_scanning_scans",
|
||||||
SecretScanningFinding = "secret_scanning_findings",
|
SecretScanningFinding = "secret_scanning_findings",
|
||||||
SecretScanningConfig = "secret_scanning_configs"
|
SecretScanningConfig = "secret_scanning_configs",
|
||||||
|
// reminders
|
||||||
|
Reminder = "reminders",
|
||||||
|
ReminderRecipient = "reminders_recipients"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TImmutableDBKeys = "id" | "createdAt" | "updatedAt" | "commitId";
|
export type TImmutableDBKeys = "id" | "createdAt" | "updatedAt" | "commitId";
|
||||||
@@ -267,6 +272,16 @@ export enum ProjectType {
|
|||||||
SecretScanning = "secret-scanning"
|
SecretScanning = "secret-scanning"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ActionProjectType {
|
||||||
|
SecretManager = ProjectType.SecretManager,
|
||||||
|
CertificateManager = ProjectType.CertificateManager,
|
||||||
|
KMS = ProjectType.KMS,
|
||||||
|
SSH = ProjectType.SSH,
|
||||||
|
SecretScanning = ProjectType.SecretScanning,
|
||||||
|
// project operations that happen on all types
|
||||||
|
Any = "any"
|
||||||
|
}
|
||||||
|
|
||||||
export enum SortDirection {
|
export enum SortDirection {
|
||||||
ASC = "asc",
|
ASC = "asc",
|
||||||
DESC = "desc"
|
DESC = "desc"
|
||||||
|
@@ -16,7 +16,7 @@ export const ProjectTemplatesSchema = z.object({
|
|||||||
orgId: z.string().uuid(),
|
orgId: z.string().uuid(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date(),
|
updatedAt: z.date(),
|
||||||
type: z.string().nullable().optional()
|
type: z.string().default("secret-manager")
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TProjectTemplates = z.infer<typeof ProjectTemplatesSchema>;
|
export type TProjectTemplates = z.infer<typeof ProjectTemplatesSchema>;
|
||||||
|
@@ -25,12 +25,13 @@ export const ProjectsSchema = z.object({
|
|||||||
kmsSecretManagerKeyId: z.string().uuid().nullable().optional(),
|
kmsSecretManagerKeyId: z.string().uuid().nullable().optional(),
|
||||||
kmsSecretManagerEncryptedDataKey: zodBuffer.nullable().optional(),
|
kmsSecretManagerEncryptedDataKey: zodBuffer.nullable().optional(),
|
||||||
description: z.string().nullable().optional(),
|
description: z.string().nullable().optional(),
|
||||||
type: z.string().nullable().optional(),
|
type: z.string(),
|
||||||
enforceCapitalization: z.boolean().default(false),
|
enforceCapitalization: z.boolean().default(false),
|
||||||
hasDeleteProtection: z.boolean().default(false).nullable().optional(),
|
hasDeleteProtection: z.boolean().default(false).nullable().optional(),
|
||||||
secretSharing: z.boolean().default(true),
|
secretSharing: z.boolean().default(true),
|
||||||
showSnapshotsLegacy: z.boolean().default(false),
|
showSnapshotsLegacy: z.boolean().default(false),
|
||||||
defaultProduct: z.string().default("secret-manager")
|
defaultProduct: z.string().nullable().optional(),
|
||||||
|
secretDetectionIgnoreValues: z.string().array().nullable().optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TProjects = z.infer<typeof ProjectsSchema>;
|
export type TProjects = z.infer<typeof ProjectsSchema>;
|
||||||
|
20
backend/src/db/schemas/reminders-recipients.ts
Normal file
20
backend/src/db/schemas/reminders-recipients.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Code generated by automation script, DO NOT EDIT.
|
||||||
|
// Automated by pulling database and generating zod schema
|
||||||
|
// To update. Just run npm run generate:schema
|
||||||
|
// Written by akhilmhdh.
|
||||||
|
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
|
export const RemindersRecipientsSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
reminderId: z.string().uuid(),
|
||||||
|
userId: z.string().uuid(),
|
||||||
|
createdAt: z.date(),
|
||||||
|
updatedAt: z.date()
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TRemindersRecipients = z.infer<typeof RemindersRecipientsSchema>;
|
||||||
|
export type TRemindersRecipientsInsert = Omit<z.input<typeof RemindersRecipientsSchema>, TImmutableDBKeys>;
|
||||||
|
export type TRemindersRecipientsUpdate = Partial<Omit<z.input<typeof RemindersRecipientsSchema>, TImmutableDBKeys>>;
|
22
backend/src/db/schemas/reminders.ts
Normal file
22
backend/src/db/schemas/reminders.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// Code generated by automation script, DO NOT EDIT.
|
||||||
|
// Automated by pulling database and generating zod schema
|
||||||
|
// To update. Just run npm run generate:schema
|
||||||
|
// Written by akhilmhdh.
|
||||||
|
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
|
export const RemindersSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
secretId: z.string().uuid().nullable().optional(),
|
||||||
|
message: z.string().nullable().optional(),
|
||||||
|
repeatDays: z.number().nullable().optional(),
|
||||||
|
nextReminderDate: z.date(),
|
||||||
|
createdAt: z.date(),
|
||||||
|
updatedAt: z.date()
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TReminders = z.infer<typeof RemindersSchema>;
|
||||||
|
export type TRemindersInsert = Omit<z.input<typeof RemindersSchema>, TImmutableDBKeys>;
|
||||||
|
export type TRemindersUpdate = Partial<Omit<z.input<typeof RemindersSchema>, TImmutableDBKeys>>;
|
@@ -0,0 +1,25 @@
|
|||||||
|
// Code generated by automation script, DO NOT EDIT.
|
||||||
|
// Automated by pulling database and generating zod schema
|
||||||
|
// To update. Just run npm run generate:schema
|
||||||
|
// Written by akhilmhdh.
|
||||||
|
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { TImmutableDBKeys } from "./models";
|
||||||
|
|
||||||
|
export const SecretApprovalPoliciesEnvironmentsSchema = z.object({
|
||||||
|
id: z.string().uuid(),
|
||||||
|
policyId: z.string().uuid(),
|
||||||
|
envId: z.string().uuid(),
|
||||||
|
createdAt: z.date(),
|
||||||
|
updatedAt: z.date()
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TSecretApprovalPoliciesEnvironments = z.infer<typeof SecretApprovalPoliciesEnvironmentsSchema>;
|
||||||
|
export type TSecretApprovalPoliciesEnvironmentsInsert = Omit<
|
||||||
|
z.input<typeof SecretApprovalPoliciesEnvironmentsSchema>,
|
||||||
|
TImmutableDBKeys
|
||||||
|
>;
|
||||||
|
export type TSecretApprovalPoliciesEnvironmentsUpdate = Partial<
|
||||||
|
Omit<z.input<typeof SecretApprovalPoliciesEnvironmentsSchema>, TImmutableDBKeys>
|
||||||
|
>;
|
@@ -17,52 +17,66 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi
|
|||||||
rateLimit: writeLimit
|
rateLimit: writeLimit
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
body: z.object({
|
body: z
|
||||||
projectSlug: z.string().trim(),
|
.object({
|
||||||
name: z.string().optional(),
|
projectSlug: z.string().trim(),
|
||||||
secretPath: z.string().trim().min(1, { message: "Secret path cannot be empty" }).transform(removeTrailingSlash),
|
name: z.string().optional(),
|
||||||
environment: z.string(),
|
secretPath: z
|
||||||
approvers: z
|
.string()
|
||||||
.discriminatedUnion("type", [
|
.trim()
|
||||||
z.object({
|
.min(1, { message: "Secret path cannot be empty" })
|
||||||
type: z.literal(ApproverType.Group),
|
.transform(removeTrailingSlash),
|
||||||
id: z.string(),
|
environment: z.string().optional(),
|
||||||
sequence: z.number().int().default(1)
|
environments: z.string().array().optional(),
|
||||||
}),
|
approvers: z
|
||||||
z.object({
|
.discriminatedUnion("type", [
|
||||||
type: z.literal(ApproverType.User),
|
z.object({
|
||||||
id: z.string().optional(),
|
type: z.literal(ApproverType.Group),
|
||||||
username: z.string().optional(),
|
id: z.string(),
|
||||||
sequence: z.number().int().default(1)
|
sequence: z.number().int().default(1)
|
||||||
|
}),
|
||||||
|
z.object({
|
||||||
|
type: z.literal(ApproverType.User),
|
||||||
|
id: z.string().optional(),
|
||||||
|
username: z.string().optional(),
|
||||||
|
sequence: z.number().int().default(1)
|
||||||
|
})
|
||||||
|
])
|
||||||
|
.array()
|
||||||
|
.max(100, "Cannot have more than 100 approvers")
|
||||||
|
.min(1, { message: "At least one approver should be provided" })
|
||||||
|
.refine(
|
||||||
|
// @ts-expect-error this is ok
|
||||||
|
(el) => el.every((i) => Boolean(i?.id) || Boolean(i?.username)),
|
||||||
|
"Must provide either username or id"
|
||||||
|
),
|
||||||
|
bypassers: z
|
||||||
|
.discriminatedUnion("type", [
|
||||||
|
z.object({ type: z.literal(BypasserType.Group), id: z.string() }),
|
||||||
|
z.object({
|
||||||
|
type: z.literal(BypasserType.User),
|
||||||
|
id: z.string().optional(),
|
||||||
|
username: z.string().optional()
|
||||||
|
})
|
||||||
|
])
|
||||||
|
.array()
|
||||||
|
.max(100, "Cannot have more than 100 bypassers")
|
||||||
|
.optional(),
|
||||||
|
approvalsRequired: z
|
||||||
|
.object({
|
||||||
|
numberOfApprovals: z.number().int(),
|
||||||
|
stepNumber: z.number().int()
|
||||||
})
|
})
|
||||||
])
|
.array()
|
||||||
.array()
|
.optional(),
|
||||||
.max(100, "Cannot have more than 100 approvers")
|
approvals: z.number().min(1).default(1),
|
||||||
.min(1, { message: "At least one approver should be provided" })
|
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard),
|
||||||
.refine(
|
allowedSelfApprovals: z.boolean().default(true)
|
||||||
// @ts-expect-error this is ok
|
})
|
||||||
(el) => el.every((i) => Boolean(i?.id) || Boolean(i?.username)),
|
.refine(
|
||||||
"Must provide either username or id"
|
(val) => Boolean(val.environment) || Boolean(val.environments),
|
||||||
),
|
"Must provide either environment or environments"
|
||||||
bypassers: z
|
),
|
||||||
.discriminatedUnion("type", [
|
|
||||||
z.object({ type: z.literal(BypasserType.Group), id: z.string() }),
|
|
||||||
z.object({ type: z.literal(BypasserType.User), id: z.string().optional(), username: z.string().optional() })
|
|
||||||
])
|
|
||||||
.array()
|
|
||||||
.max(100, "Cannot have more than 100 bypassers")
|
|
||||||
.optional(),
|
|
||||||
approvalsRequired: z
|
|
||||||
.object({
|
|
||||||
numberOfApprovals: z.number().int(),
|
|
||||||
stepNumber: z.number().int()
|
|
||||||
})
|
|
||||||
.array()
|
|
||||||
.optional(),
|
|
||||||
approvals: z.number().min(1).default(1),
|
|
||||||
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard),
|
|
||||||
allowedSelfApprovals: z.boolean().default(true)
|
|
||||||
}),
|
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
approval: sapPubSchema
|
approval: sapPubSchema
|
||||||
@@ -78,7 +92,8 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi
|
|||||||
actorOrgId: req.permission.orgId,
|
actorOrgId: req.permission.orgId,
|
||||||
...req.body,
|
...req.body,
|
||||||
projectSlug: req.body.projectSlug,
|
projectSlug: req.body.projectSlug,
|
||||||
name: req.body.name ?? `${req.body.environment}-${nanoid(3)}`,
|
name:
|
||||||
|
req.body.name ?? `${req.body.environment || req.body.environments?.join("-").substring(0, 250)}-${nanoid(3)}`,
|
||||||
enforcementLevel: req.body.enforcementLevel
|
enforcementLevel: req.body.enforcementLevel
|
||||||
});
|
});
|
||||||
return { approval };
|
return { approval };
|
||||||
@@ -211,6 +226,7 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi
|
|||||||
approvals: z.number().min(1).optional(),
|
approvals: z.number().min(1).optional(),
|
||||||
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard),
|
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard),
|
||||||
allowedSelfApprovals: z.boolean().default(true),
|
allowedSelfApprovals: z.boolean().default(true),
|
||||||
|
environments: z.array(z.string()).optional(),
|
||||||
approvalsRequired: z
|
approvalsRequired: z
|
||||||
.object({
|
.object({
|
||||||
numberOfApprovals: z.number().int(),
|
numberOfApprovals: z.number().int(),
|
||||||
|
@@ -3,11 +3,14 @@ import { z } from "zod";
|
|||||||
|
|
||||||
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
||||||
import { removeTrailingSlash } from "@app/lib/fn";
|
import { removeTrailingSlash } from "@app/lib/fn";
|
||||||
import { readLimit } from "@app/server/config/rateLimiter";
|
import { isValidFolderName } from "@app/lib/validator";
|
||||||
|
import { readLimit, secretsLimit } from "@app/server/config/rateLimiter";
|
||||||
|
import { SecretNameSchema } from "@app/server/lib/schemas";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { booleanSchema } from "@app/server/routes/sanitizedSchemas";
|
import { booleanSchema } from "@app/server/routes/sanitizedSchemas";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
import { commitChangesResponseSchema, resourceChangeSchema } from "@app/services/folder-commit/folder-commit-schemas";
|
import { commitChangesResponseSchema, resourceChangeSchema } from "@app/services/folder-commit/folder-commit-schemas";
|
||||||
|
import { ResourceMetadataSchema } from "@app/services/resource-metadata/resource-metadata-schema";
|
||||||
|
|
||||||
const commitHistoryItemSchema = z.object({
|
const commitHistoryItemSchema = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
@@ -413,4 +416,166 @@ export const registerPITRouter = async (server: FastifyZodProvider) => {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.route({
|
||||||
|
method: "POST",
|
||||||
|
url: "/batch/commit",
|
||||||
|
config: {
|
||||||
|
rateLimit: secretsLimit
|
||||||
|
},
|
||||||
|
schema: {
|
||||||
|
hide: true,
|
||||||
|
description: "Commit changes",
|
||||||
|
security: [
|
||||||
|
{
|
||||||
|
bearerAuth: []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
body: z.object({
|
||||||
|
projectId: z.string().trim(),
|
||||||
|
environment: z.string().trim(),
|
||||||
|
secretPath: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||||
|
message: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.min(1)
|
||||||
|
.max(255)
|
||||||
|
.refine((message) => message.trim() !== "", {
|
||||||
|
message: "Commit message cannot be empty"
|
||||||
|
}),
|
||||||
|
changes: z.object({
|
||||||
|
secrets: z.object({
|
||||||
|
create: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
secretKey: SecretNameSchema,
|
||||||
|
secretValue: z.string().transform((val) => (val.at(-1) === "\n" ? `${val.trim()}\n` : val.trim())),
|
||||||
|
secretComment: z.string().trim().optional().default(""),
|
||||||
|
skipMultilineEncoding: z.boolean().optional(),
|
||||||
|
metadata: z.record(z.string()).optional(),
|
||||||
|
secretMetadata: ResourceMetadataSchema.optional(),
|
||||||
|
tagIds: z.string().array().optional()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
update: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
secretKey: SecretNameSchema,
|
||||||
|
newSecretName: SecretNameSchema.optional(),
|
||||||
|
secretValue: z
|
||||||
|
.string()
|
||||||
|
.transform((val) => (val.at(-1) === "\n" ? `${val.trim()}\n` : val.trim()))
|
||||||
|
.optional(),
|
||||||
|
secretComment: z.string().trim().optional().default(""),
|
||||||
|
skipMultilineEncoding: z.boolean().optional(),
|
||||||
|
metadata: z.record(z.string()).optional(),
|
||||||
|
secretMetadata: ResourceMetadataSchema.optional(),
|
||||||
|
tagIds: z.string().array().optional()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
delete: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
secretKey: SecretNameSchema
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional()
|
||||||
|
}),
|
||||||
|
folders: z.object({
|
||||||
|
create: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
folderName: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.refine((name) => isValidFolderName(name), {
|
||||||
|
message: "Invalid folder name. Only alphanumeric characters, dashes, and underscores are allowed."
|
||||||
|
}),
|
||||||
|
description: z.string().optional()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
update: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
folderName: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.refine((name) => isValidFolderName(name), {
|
||||||
|
message: "Invalid folder name. Only alphanumeric characters, dashes, and underscores are allowed."
|
||||||
|
}),
|
||||||
|
description: z.string().nullable().optional(),
|
||||||
|
id: z.string()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
delete: z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
folderName: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.refine((name) => isValidFolderName(name), {
|
||||||
|
message: "Invalid folder name. Only alphanumeric characters, dashes, and underscores are allowed."
|
||||||
|
}),
|
||||||
|
id: z.string()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.optional()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
response: {
|
||||||
|
200: z.object({
|
||||||
|
message: z.string()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
|
handler: async (req) => {
|
||||||
|
const result = await server.services.pit.processNewCommitRaw({
|
||||||
|
actorId: req.permission.id,
|
||||||
|
actor: req.permission.type,
|
||||||
|
actorOrgId: req.permission.orgId,
|
||||||
|
actorAuthMethod: req.permission.authMethod,
|
||||||
|
projectId: req.body.projectId,
|
||||||
|
environment: req.body.environment,
|
||||||
|
secretPath: req.body.secretPath,
|
||||||
|
message: req.body.message,
|
||||||
|
changes: {
|
||||||
|
secrets: req.body.changes.secrets,
|
||||||
|
folders: req.body.changes.folders
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.services.auditLog.createAuditLog({
|
||||||
|
...req.auditLogInfo,
|
||||||
|
projectId: req.body.projectId,
|
||||||
|
event: {
|
||||||
|
type: EventType.PIT_PROCESS_NEW_COMMIT_RAW,
|
||||||
|
metadata: {
|
||||||
|
commitId: result.commitId,
|
||||||
|
approvalId: result.approvalId,
|
||||||
|
projectId: req.body.projectId,
|
||||||
|
environment: req.body.environment,
|
||||||
|
secretPath: req.body.secretPath,
|
||||||
|
message: req.body.message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for await (const event of result.secretMutationEvents) {
|
||||||
|
await server.services.auditLog.createAuditLog({
|
||||||
|
...req.auditLogInfo,
|
||||||
|
orgId: req.permission.orgId,
|
||||||
|
projectId: req.body.projectId,
|
||||||
|
event
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { message: "success" };
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { ProjectMembershipRole, ProjectTemplatesSchema } from "@app/db/schemas";
|
import { ProjectMembershipRole, ProjectTemplatesSchema, ProjectType } from "@app/db/schemas";
|
||||||
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
||||||
import { ProjectPermissionV2Schema } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionV2Schema } from "@app/ee/services/permission/project-permission";
|
||||||
import { isInfisicalProjectTemplate } from "@app/ee/services/project-template/project-template-fns";
|
import { isInfisicalProjectTemplate } from "@app/ee/services/project-template/project-template-fns";
|
||||||
@@ -104,6 +104,9 @@ export const registerProjectTemplateRouter = async (server: FastifyZodProvider)
|
|||||||
hide: false,
|
hide: false,
|
||||||
tags: [ApiDocsTags.ProjectTemplates],
|
tags: [ApiDocsTags.ProjectTemplates],
|
||||||
description: "List project templates for the current organization.",
|
description: "List project templates for the current organization.",
|
||||||
|
querystring: z.object({
|
||||||
|
type: z.nativeEnum(ProjectType).optional().describe(ProjectTemplates.LIST.type)
|
||||||
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
projectTemplates: SanitizedProjectTemplateSchema.array()
|
projectTemplates: SanitizedProjectTemplateSchema.array()
|
||||||
@@ -112,7 +115,10 @@ export const registerProjectTemplateRouter = async (server: FastifyZodProvider)
|
|||||||
},
|
},
|
||||||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
const projectTemplates = await server.services.projectTemplate.listProjectTemplatesByOrg(req.permission);
|
const projectTemplates = await server.services.projectTemplate.listProjectTemplatesByOrg(
|
||||||
|
req.permission,
|
||||||
|
req.query.type
|
||||||
|
);
|
||||||
|
|
||||||
const auditTemplates = projectTemplates.filter((template) => !isInfisicalProjectTemplate(template.name));
|
const auditTemplates = projectTemplates.filter((template) => !isInfisicalProjectTemplate(template.name));
|
||||||
|
|
||||||
@@ -191,6 +197,7 @@ export const registerProjectTemplateRouter = async (server: FastifyZodProvider)
|
|||||||
.describe(ProjectTemplates.CREATE.name),
|
.describe(ProjectTemplates.CREATE.name),
|
||||||
description: z.string().max(256).trim().optional().describe(ProjectTemplates.CREATE.description),
|
description: z.string().max(256).trim().optional().describe(ProjectTemplates.CREATE.description),
|
||||||
roles: ProjectTemplateRolesSchema.default([]).describe(ProjectTemplates.CREATE.roles),
|
roles: ProjectTemplateRolesSchema.default([]).describe(ProjectTemplates.CREATE.roles),
|
||||||
|
type: z.nativeEnum(ProjectType).describe(ProjectTemplates.CREATE.type),
|
||||||
environments: ProjectTemplateEnvironmentsSchema.describe(ProjectTemplates.CREATE.environments).optional()
|
environments: ProjectTemplateEnvironmentsSchema.describe(ProjectTemplates.CREATE.environments).optional()
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
|
@@ -17,34 +17,45 @@ export const registerSecretApprovalPolicyRouter = async (server: FastifyZodProvi
|
|||||||
rateLimit: writeLimit
|
rateLimit: writeLimit
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
body: z.object({
|
body: z
|
||||||
workspaceId: z.string(),
|
.object({
|
||||||
name: z.string().optional(),
|
workspaceId: z.string(),
|
||||||
environment: z.string(),
|
name: z.string().optional(),
|
||||||
secretPath: z
|
environment: z.string().optional(),
|
||||||
.string()
|
environments: z.string().array().optional(),
|
||||||
.min(1, { message: "Secret path cannot be empty" })
|
secretPath: z
|
||||||
.transform((val) => removeTrailingSlash(val)),
|
.string()
|
||||||
approvers: z
|
.min(1, { message: "Secret path cannot be empty" })
|
||||||
.discriminatedUnion("type", [
|
.transform((val) => removeTrailingSlash(val)),
|
||||||
z.object({ type: z.literal(ApproverType.Group), id: z.string() }),
|
approvers: z
|
||||||
z.object({ type: z.literal(ApproverType.User), id: z.string().optional(), username: z.string().optional() })
|
.discriminatedUnion("type", [
|
||||||
])
|
z.object({ type: z.literal(ApproverType.Group), id: z.string() }),
|
||||||
.array()
|
z.object({
|
||||||
.min(1, { message: "At least one approver should be provided" })
|
type: z.literal(ApproverType.User),
|
||||||
.max(100, "Cannot have more than 100 approvers"),
|
id: z.string().optional(),
|
||||||
bypassers: z
|
username: z.string().optional()
|
||||||
.discriminatedUnion("type", [
|
})
|
||||||
z.object({ type: z.literal(BypasserType.Group), id: z.string() }),
|
])
|
||||||
z.object({ type: z.literal(BypasserType.User), id: z.string().optional(), username: z.string().optional() })
|
.array()
|
||||||
])
|
.min(1, { message: "At least one approver should be provided" })
|
||||||
.array()
|
.max(100, "Cannot have more than 100 approvers"),
|
||||||
.max(100, "Cannot have more than 100 bypassers")
|
bypassers: z
|
||||||
.optional(),
|
.discriminatedUnion("type", [
|
||||||
approvals: z.number().min(1).default(1),
|
z.object({ type: z.literal(BypasserType.Group), id: z.string() }),
|
||||||
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard),
|
z.object({
|
||||||
allowedSelfApprovals: z.boolean().default(true)
|
type: z.literal(BypasserType.User),
|
||||||
}),
|
id: z.string().optional(),
|
||||||
|
username: z.string().optional()
|
||||||
|
})
|
||||||
|
])
|
||||||
|
.array()
|
||||||
|
.max(100, "Cannot have more than 100 bypassers")
|
||||||
|
.optional(),
|
||||||
|
approvals: z.number().min(1).default(1),
|
||||||
|
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard),
|
||||||
|
allowedSelfApprovals: z.boolean().default(true)
|
||||||
|
})
|
||||||
|
.refine((data) => data.environment || data.environments, "At least one environment should be provided"),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
approval: sapPubSchema
|
approval: sapPubSchema
|
||||||
@@ -60,7 +71,7 @@ export const registerSecretApprovalPolicyRouter = async (server: FastifyZodProvi
|
|||||||
actorOrgId: req.permission.orgId,
|
actorOrgId: req.permission.orgId,
|
||||||
projectId: req.body.workspaceId,
|
projectId: req.body.workspaceId,
|
||||||
...req.body,
|
...req.body,
|
||||||
name: req.body.name ?? `${req.body.environment}-${nanoid(3)}`,
|
name: req.body.name ?? `${req.body.environment || req.body.environments?.join(",")}-${nanoid(3)}`,
|
||||||
enforcementLevel: req.body.enforcementLevel
|
enforcementLevel: req.body.enforcementLevel
|
||||||
});
|
});
|
||||||
return { approval };
|
return { approval };
|
||||||
@@ -103,7 +114,8 @@ export const registerSecretApprovalPolicyRouter = async (server: FastifyZodProvi
|
|||||||
.optional()
|
.optional()
|
||||||
.transform((val) => (val ? removeTrailingSlash(val) : undefined)),
|
.transform((val) => (val ? removeTrailingSlash(val) : undefined)),
|
||||||
enforcementLevel: z.nativeEnum(EnforcementLevel).optional(),
|
enforcementLevel: z.nativeEnum(EnforcementLevel).optional(),
|
||||||
allowedSelfApprovals: z.boolean().default(true)
|
allowedSelfApprovals: z.boolean().default(true),
|
||||||
|
environments: z.array(z.string()).optional()
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
|
@@ -6,6 +6,7 @@ import { registerAzureClientSecretRotationRouter } from "./azure-client-secret-r
|
|||||||
import { registerLdapPasswordRotationRouter } from "./ldap-password-rotation-router";
|
import { registerLdapPasswordRotationRouter } from "./ldap-password-rotation-router";
|
||||||
import { registerMsSqlCredentialsRotationRouter } from "./mssql-credentials-rotation-router";
|
import { registerMsSqlCredentialsRotationRouter } from "./mssql-credentials-rotation-router";
|
||||||
import { registerMySqlCredentialsRotationRouter } from "./mysql-credentials-rotation-router";
|
import { registerMySqlCredentialsRotationRouter } from "./mysql-credentials-rotation-router";
|
||||||
|
import { registerOktaClientSecretRotationRouter } from "./okta-client-secret-rotation-router";
|
||||||
import { registerOracleDBCredentialsRotationRouter } from "./oracledb-credentials-rotation-router";
|
import { registerOracleDBCredentialsRotationRouter } from "./oracledb-credentials-rotation-router";
|
||||||
import { registerPostgresCredentialsRotationRouter } from "./postgres-credentials-rotation-router";
|
import { registerPostgresCredentialsRotationRouter } from "./postgres-credentials-rotation-router";
|
||||||
|
|
||||||
@@ -22,5 +23,6 @@ export const SECRET_ROTATION_REGISTER_ROUTER_MAP: Record<
|
|||||||
[SecretRotation.Auth0ClientSecret]: registerAuth0ClientSecretRotationRouter,
|
[SecretRotation.Auth0ClientSecret]: registerAuth0ClientSecretRotationRouter,
|
||||||
[SecretRotation.AzureClientSecret]: registerAzureClientSecretRotationRouter,
|
[SecretRotation.AzureClientSecret]: registerAzureClientSecretRotationRouter,
|
||||||
[SecretRotation.AwsIamUserSecret]: registerAwsIamUserSecretRotationRouter,
|
[SecretRotation.AwsIamUserSecret]: registerAwsIamUserSecretRotationRouter,
|
||||||
[SecretRotation.LdapPassword]: registerLdapPasswordRotationRouter
|
[SecretRotation.LdapPassword]: registerLdapPasswordRotationRouter,
|
||||||
|
[SecretRotation.OktaClientSecret]: registerOktaClientSecretRotationRouter
|
||||||
};
|
};
|
||||||
|
@@ -0,0 +1,19 @@
|
|||||||
|
import {
|
||||||
|
CreateOktaClientSecretRotationSchema,
|
||||||
|
OktaClientSecretRotationGeneratedCredentialsSchema,
|
||||||
|
OktaClientSecretRotationSchema,
|
||||||
|
UpdateOktaClientSecretRotationSchema
|
||||||
|
} from "@app/ee/services/secret-rotation-v2/okta-client-secret";
|
||||||
|
import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
|
||||||
|
|
||||||
|
import { registerSecretRotationEndpoints } from "./secret-rotation-v2-endpoints";
|
||||||
|
|
||||||
|
export const registerOktaClientSecretRotationRouter = async (server: FastifyZodProvider) =>
|
||||||
|
registerSecretRotationEndpoints({
|
||||||
|
type: SecretRotation.OktaClientSecret,
|
||||||
|
server,
|
||||||
|
responseSchema: OktaClientSecretRotationSchema,
|
||||||
|
createSchema: CreateOktaClientSecretRotationSchema,
|
||||||
|
updateSchema: UpdateOktaClientSecretRotationSchema,
|
||||||
|
generatedCredentialsSchema: OktaClientSecretRotationGeneratedCredentialsSchema
|
||||||
|
});
|
@@ -315,10 +315,12 @@ export const registerSecretRotationEndpoints = <
|
|||||||
querystring: z.object({
|
querystring: z.object({
|
||||||
deleteSecrets: z
|
deleteSecrets: z
|
||||||
.enum(["true", "false"])
|
.enum(["true", "false"])
|
||||||
|
.optional()
|
||||||
.transform((value) => value === "true")
|
.transform((value) => value === "true")
|
||||||
.describe(SecretRotations.DELETE(type).deleteSecrets),
|
.describe(SecretRotations.DELETE(type).deleteSecrets),
|
||||||
revokeGeneratedCredentials: z
|
revokeGeneratedCredentials: z
|
||||||
.enum(["true", "false"])
|
.enum(["true", "false"])
|
||||||
|
.optional()
|
||||||
.transform((value) => value === "true")
|
.transform((value) => value === "true")
|
||||||
.describe(SecretRotations.DELETE(type).revokeGeneratedCredentials)
|
.describe(SecretRotations.DELETE(type).revokeGeneratedCredentials)
|
||||||
}),
|
}),
|
||||||
|
@@ -7,6 +7,7 @@ import { AzureClientSecretRotationListItemSchema } from "@app/ee/services/secret
|
|||||||
import { LdapPasswordRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/ldap-password";
|
import { LdapPasswordRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/ldap-password";
|
||||||
import { MsSqlCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/mssql-credentials";
|
import { MsSqlCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/mssql-credentials";
|
||||||
import { MySqlCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/mysql-credentials";
|
import { MySqlCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/mysql-credentials";
|
||||||
|
import { OktaClientSecretRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/okta-client-secret";
|
||||||
import { OracleDBCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/oracledb-credentials";
|
import { OracleDBCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/oracledb-credentials";
|
||||||
import { PostgresCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/postgres-credentials";
|
import { PostgresCredentialsRotationListItemSchema } from "@app/ee/services/secret-rotation-v2/postgres-credentials";
|
||||||
import { SecretRotationV2Schema } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-union-schema";
|
import { SecretRotationV2Schema } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-union-schema";
|
||||||
@@ -23,7 +24,8 @@ const SecretRotationV2OptionsSchema = z.discriminatedUnion("type", [
|
|||||||
Auth0ClientSecretRotationListItemSchema,
|
Auth0ClientSecretRotationListItemSchema,
|
||||||
AzureClientSecretRotationListItemSchema,
|
AzureClientSecretRotationListItemSchema,
|
||||||
AwsIamUserSecretRotationListItemSchema,
|
AwsIamUserSecretRotationListItemSchema,
|
||||||
LdapPasswordRotationListItemSchema
|
LdapPasswordRotationListItemSchema,
|
||||||
|
OktaClientSecretRotationListItemSchema
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const registerSecretRotationV2Router = async (server: FastifyZodProvider) => {
|
export const registerSecretRotationV2Router = async (server: FastifyZodProvider) => {
|
||||||
|
@@ -26,6 +26,7 @@ export interface TAccessApprovalPolicyDALFactory
|
|||||||
>,
|
>,
|
||||||
customFilter?: {
|
customFilter?: {
|
||||||
policyId?: string;
|
policyId?: string;
|
||||||
|
envId?: string;
|
||||||
},
|
},
|
||||||
tx?: Knex
|
tx?: Knex
|
||||||
) => Promise<
|
) => Promise<
|
||||||
@@ -55,11 +56,6 @@ export interface TAccessApprovalPolicyDALFactory
|
|||||||
allowedSelfApprovals: boolean;
|
allowedSelfApprovals: boolean;
|
||||||
secretPath: string;
|
secretPath: string;
|
||||||
deletedAt?: Date | null | undefined;
|
deletedAt?: Date | null | undefined;
|
||||||
environment: {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
slug: string;
|
|
||||||
};
|
|
||||||
projectId: string;
|
projectId: string;
|
||||||
bypassers: (
|
bypassers: (
|
||||||
| {
|
| {
|
||||||
@@ -72,6 +68,11 @@ export interface TAccessApprovalPolicyDALFactory
|
|||||||
type: BypasserType.Group;
|
type: BypasserType.Group;
|
||||||
}
|
}
|
||||||
)[];
|
)[];
|
||||||
|
environments: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
}[];
|
||||||
}[]
|
}[]
|
||||||
>;
|
>;
|
||||||
findById: (
|
findById: (
|
||||||
@@ -95,11 +96,11 @@ export interface TAccessApprovalPolicyDALFactory
|
|||||||
allowedSelfApprovals: boolean;
|
allowedSelfApprovals: boolean;
|
||||||
secretPath: string;
|
secretPath: string;
|
||||||
deletedAt?: Date | null | undefined;
|
deletedAt?: Date | null | undefined;
|
||||||
environment: {
|
environments: {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
};
|
}[];
|
||||||
projectId: string;
|
projectId: string;
|
||||||
}
|
}
|
||||||
| undefined
|
| undefined
|
||||||
@@ -143,6 +144,26 @@ export interface TAccessApprovalPolicyDALFactory
|
|||||||
}
|
}
|
||||||
| undefined
|
| undefined
|
||||||
>;
|
>;
|
||||||
|
findPolicyByEnvIdAndSecretPath: (
|
||||||
|
{ envIds, secretPath }: { envIds: string[]; secretPath: string },
|
||||||
|
tx?: Knex
|
||||||
|
) => Promise<{
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
createdAt: Date;
|
||||||
|
updatedAt: Date;
|
||||||
|
approvals: number;
|
||||||
|
enforcementLevel: string;
|
||||||
|
allowedSelfApprovals: boolean;
|
||||||
|
secretPath: string;
|
||||||
|
deletedAt?: Date | null | undefined;
|
||||||
|
environments: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
}[];
|
||||||
|
projectId: string;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TAccessApprovalPolicyServiceFactory {
|
export interface TAccessApprovalPolicyServiceFactory {
|
||||||
@@ -367,6 +388,7 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient): TAccessApprovalPo
|
|||||||
filter: TFindFilter<TAccessApprovalPolicies & { projectId: string }>,
|
filter: TFindFilter<TAccessApprovalPolicies & { projectId: string }>,
|
||||||
customFilter?: {
|
customFilter?: {
|
||||||
policyId?: string;
|
policyId?: string;
|
||||||
|
envId?: string;
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const result = await tx(TableName.AccessApprovalPolicy)
|
const result = await tx(TableName.AccessApprovalPolicy)
|
||||||
@@ -377,7 +399,17 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient): TAccessApprovalPo
|
|||||||
void qb.where(`${TableName.AccessApprovalPolicy}.id`, "=", customFilter.policyId);
|
void qb.where(`${TableName.AccessApprovalPolicy}.id`, "=", customFilter.policyId);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.join(TableName.Environment, `${TableName.AccessApprovalPolicy}.envId`, `${TableName.Environment}.id`)
|
.join(
|
||||||
|
TableName.AccessApprovalPolicyEnvironment,
|
||||||
|
`${TableName.AccessApprovalPolicy}.id`,
|
||||||
|
`${TableName.AccessApprovalPolicyEnvironment}.policyId`
|
||||||
|
)
|
||||||
|
.join(TableName.Environment, `${TableName.AccessApprovalPolicyEnvironment}.envId`, `${TableName.Environment}.id`)
|
||||||
|
.where((qb) => {
|
||||||
|
if (customFilter?.envId) {
|
||||||
|
void qb.where(`${TableName.AccessApprovalPolicyEnvironment}.envId`, "=", customFilter.envId);
|
||||||
|
}
|
||||||
|
})
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
TableName.AccessApprovalPolicyApprover,
|
TableName.AccessApprovalPolicyApprover,
|
||||||
`${TableName.AccessApprovalPolicy}.id`,
|
`${TableName.AccessApprovalPolicy}.id`,
|
||||||
@@ -404,7 +436,7 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient): TAccessApprovalPo
|
|||||||
.select(tx.ref("bypasserGroupId").withSchema(TableName.AccessApprovalPolicyBypasser))
|
.select(tx.ref("bypasserGroupId").withSchema(TableName.AccessApprovalPolicyBypasser))
|
||||||
.select(tx.ref("name").withSchema(TableName.Environment).as("envName"))
|
.select(tx.ref("name").withSchema(TableName.Environment).as("envName"))
|
||||||
.select(tx.ref("slug").withSchema(TableName.Environment).as("envSlug"))
|
.select(tx.ref("slug").withSchema(TableName.Environment).as("envSlug"))
|
||||||
.select(tx.ref("id").withSchema(TableName.Environment).as("envId"))
|
.select(tx.ref("id").withSchema(TableName.Environment).as("environmentId"))
|
||||||
.select(tx.ref("projectId").withSchema(TableName.Environment))
|
.select(tx.ref("projectId").withSchema(TableName.Environment))
|
||||||
.select(selectAllTableCols(TableName.AccessApprovalPolicy));
|
.select(selectAllTableCols(TableName.AccessApprovalPolicy));
|
||||||
|
|
||||||
@@ -448,6 +480,15 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient): TAccessApprovalPo
|
|||||||
sequence: approverSequence,
|
sequence: approverSequence,
|
||||||
approvalsRequired
|
approvalsRequired
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "environmentId",
|
||||||
|
label: "environments" as const,
|
||||||
|
mapper: ({ environmentId: id, envName, envSlug }) => ({
|
||||||
|
id,
|
||||||
|
name: envName,
|
||||||
|
slug: envSlug
|
||||||
|
})
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -470,11 +511,6 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient): TAccessApprovalPo
|
|||||||
data: docs,
|
data: docs,
|
||||||
key: "id",
|
key: "id",
|
||||||
parentMapper: (data) => ({
|
parentMapper: (data) => ({
|
||||||
environment: {
|
|
||||||
id: data.envId,
|
|
||||||
name: data.envName,
|
|
||||||
slug: data.envSlug
|
|
||||||
},
|
|
||||||
projectId: data.projectId,
|
projectId: data.projectId,
|
||||||
...AccessApprovalPoliciesSchema.parse(data)
|
...AccessApprovalPoliciesSchema.parse(data)
|
||||||
// secretPath: data.secretPath || undefined,
|
// secretPath: data.secretPath || undefined,
|
||||||
@@ -517,6 +553,15 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient): TAccessApprovalPo
|
|||||||
id,
|
id,
|
||||||
type: BypasserType.Group as const
|
type: BypasserType.Group as const
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "environmentId",
|
||||||
|
label: "environments" as const,
|
||||||
|
mapper: ({ environmentId: id, envName, envSlug }) => ({
|
||||||
|
id,
|
||||||
|
name: envName,
|
||||||
|
slug: envSlug
|
||||||
|
})
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -545,14 +590,20 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient): TAccessApprovalPo
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
buildFindFilter(
|
buildFindFilter(
|
||||||
{
|
{
|
||||||
envId,
|
|
||||||
secretPath
|
secretPath
|
||||||
},
|
},
|
||||||
TableName.AccessApprovalPolicy
|
TableName.AccessApprovalPolicy
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.join(
|
||||||
|
TableName.AccessApprovalPolicyEnvironment,
|
||||||
|
`${TableName.AccessApprovalPolicyEnvironment}.policyId`,
|
||||||
|
`${TableName.AccessApprovalPolicy}.id`
|
||||||
|
)
|
||||||
|
.where(`${TableName.AccessApprovalPolicyEnvironment}.envId`, "=", envId)
|
||||||
.orderBy("deletedAt", "desc")
|
.orderBy("deletedAt", "desc")
|
||||||
.orderByRaw(`"deletedAt" IS NULL`)
|
.orderByRaw(`"deletedAt" IS NULL`)
|
||||||
|
.select(selectAllTableCols(TableName.AccessApprovalPolicy))
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -561,5 +612,81 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient): TAccessApprovalPo
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return { ...accessApprovalPolicyOrm, find, findById, softDeleteById, findLastValidPolicy };
|
const findPolicyByEnvIdAndSecretPath: TAccessApprovalPolicyDALFactory["findPolicyByEnvIdAndSecretPath"] = async (
|
||||||
|
{ envIds, secretPath },
|
||||||
|
tx
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const docs = await (tx || db.replicaNode())(TableName.AccessApprovalPolicy)
|
||||||
|
.join(
|
||||||
|
TableName.AccessApprovalPolicyEnvironment,
|
||||||
|
`${TableName.AccessApprovalPolicyEnvironment}.policyId`,
|
||||||
|
`${TableName.AccessApprovalPolicy}.id`
|
||||||
|
)
|
||||||
|
.join(
|
||||||
|
TableName.Environment,
|
||||||
|
`${TableName.AccessApprovalPolicyEnvironment}.envId`,
|
||||||
|
`${TableName.Environment}.id`
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
|
buildFindFilter(
|
||||||
|
{
|
||||||
|
$in: {
|
||||||
|
envId: envIds
|
||||||
|
}
|
||||||
|
},
|
||||||
|
TableName.AccessApprovalPolicyEnvironment
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
|
buildFindFilter(
|
||||||
|
{
|
||||||
|
secretPath
|
||||||
|
},
|
||||||
|
TableName.AccessApprovalPolicy
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.whereNull(`${TableName.AccessApprovalPolicy}.deletedAt`)
|
||||||
|
.orderBy("deletedAt", "desc")
|
||||||
|
.orderByRaw(`"deletedAt" IS NULL`)
|
||||||
|
.select(selectAllTableCols(TableName.AccessApprovalPolicy))
|
||||||
|
.select(db.ref("name").withSchema(TableName.Environment).as("envName"))
|
||||||
|
.select(db.ref("slug").withSchema(TableName.Environment).as("envSlug"))
|
||||||
|
.select(db.ref("id").withSchema(TableName.Environment).as("environmentId"))
|
||||||
|
.select(db.ref("projectId").withSchema(TableName.Environment));
|
||||||
|
const formattedDocs = sqlNestRelationships({
|
||||||
|
data: docs,
|
||||||
|
key: "id",
|
||||||
|
parentMapper: (data) => ({
|
||||||
|
projectId: data.projectId,
|
||||||
|
...AccessApprovalPoliciesSchema.parse(data)
|
||||||
|
}),
|
||||||
|
childrenMapper: [
|
||||||
|
{
|
||||||
|
key: "environmentId",
|
||||||
|
label: "environments" as const,
|
||||||
|
mapper: ({ environmentId: id, envName, envSlug }) => ({
|
||||||
|
id,
|
||||||
|
name: envName,
|
||||||
|
slug: envSlug
|
||||||
|
})
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
return formattedDocs?.[0];
|
||||||
|
} catch (error) {
|
||||||
|
throw new DatabaseError({ error, name: "findPolicyByEnvIdAndSecretPath" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...accessApprovalPolicyOrm,
|
||||||
|
find,
|
||||||
|
findById,
|
||||||
|
softDeleteById,
|
||||||
|
findLastValidPolicy,
|
||||||
|
findPolicyByEnvIdAndSecretPath
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
@@ -0,0 +1,32 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { TDbClient } from "@app/db";
|
||||||
|
import { TableName } from "@app/db/schemas";
|
||||||
|
import { DatabaseError } from "@app/lib/errors";
|
||||||
|
import { buildFindFilter, ormify, selectAllTableCols } from "@app/lib/knex";
|
||||||
|
|
||||||
|
export type TAccessApprovalPolicyEnvironmentDALFactory = ReturnType<typeof accessApprovalPolicyEnvironmentDALFactory>;
|
||||||
|
|
||||||
|
export const accessApprovalPolicyEnvironmentDALFactory = (db: TDbClient) => {
|
||||||
|
const accessApprovalPolicyEnvironmentOrm = ormify(db, TableName.AccessApprovalPolicyEnvironment);
|
||||||
|
|
||||||
|
const findAvailablePoliciesByEnvId = async (envId: string, tx?: Knex) => {
|
||||||
|
try {
|
||||||
|
const docs = await (tx || db.replicaNode())(TableName.AccessApprovalPolicyEnvironment)
|
||||||
|
.join(
|
||||||
|
TableName.AccessApprovalPolicy,
|
||||||
|
`${TableName.AccessApprovalPolicyEnvironment}.policyId`,
|
||||||
|
`${TableName.AccessApprovalPolicy}.id`
|
||||||
|
)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
|
.where(buildFindFilter({ envId }, TableName.AccessApprovalPolicyEnvironment))
|
||||||
|
.whereNull(`${TableName.AccessApprovalPolicy}.deletedAt`)
|
||||||
|
.select(selectAllTableCols(TableName.AccessApprovalPolicyEnvironment));
|
||||||
|
return docs;
|
||||||
|
} catch (error) {
|
||||||
|
throw new DatabaseError({ error, name: "findAvailablePoliciesByEnvId" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return { ...accessApprovalPolicyEnvironmentOrm, findAvailablePoliciesByEnvId };
|
||||||
|
};
|
@@ -1,5 +1,6 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
@@ -20,6 +21,7 @@ import {
|
|||||||
TAccessApprovalPolicyBypasserDALFactory
|
TAccessApprovalPolicyBypasserDALFactory
|
||||||
} from "./access-approval-policy-approver-dal";
|
} from "./access-approval-policy-approver-dal";
|
||||||
import { TAccessApprovalPolicyDALFactory } from "./access-approval-policy-dal";
|
import { TAccessApprovalPolicyDALFactory } from "./access-approval-policy-dal";
|
||||||
|
import { TAccessApprovalPolicyEnvironmentDALFactory } from "./access-approval-policy-environment-dal";
|
||||||
import {
|
import {
|
||||||
ApproverType,
|
ApproverType,
|
||||||
BypasserType,
|
BypasserType,
|
||||||
@@ -44,12 +46,14 @@ type TAccessApprovalPolicyServiceFactoryDep = {
|
|||||||
additionalPrivilegeDAL: Pick<TProjectUserAdditionalPrivilegeDALFactory, "delete">;
|
additionalPrivilegeDAL: Pick<TProjectUserAdditionalPrivilegeDALFactory, "delete">;
|
||||||
accessApprovalRequestReviewerDAL: Pick<TAccessApprovalRequestReviewerDALFactory, "update" | "delete">;
|
accessApprovalRequestReviewerDAL: Pick<TAccessApprovalRequestReviewerDALFactory, "update" | "delete">;
|
||||||
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "find">;
|
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "find">;
|
||||||
|
accessApprovalPolicyEnvironmentDAL: TAccessApprovalPolicyEnvironmentDALFactory;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const accessApprovalPolicyServiceFactory = ({
|
export const accessApprovalPolicyServiceFactory = ({
|
||||||
accessApprovalPolicyDAL,
|
accessApprovalPolicyDAL,
|
||||||
accessApprovalPolicyApproverDAL,
|
accessApprovalPolicyApproverDAL,
|
||||||
accessApprovalPolicyBypasserDAL,
|
accessApprovalPolicyBypasserDAL,
|
||||||
|
accessApprovalPolicyEnvironmentDAL,
|
||||||
groupDAL,
|
groupDAL,
|
||||||
permissionService,
|
permissionService,
|
||||||
projectEnvDAL,
|
projectEnvDAL,
|
||||||
@@ -62,21 +66,22 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
}: TAccessApprovalPolicyServiceFactoryDep): TAccessApprovalPolicyServiceFactory => {
|
}: TAccessApprovalPolicyServiceFactoryDep): TAccessApprovalPolicyServiceFactory => {
|
||||||
const $policyExists = async ({
|
const $policyExists = async ({
|
||||||
envId,
|
envId,
|
||||||
|
envIds,
|
||||||
secretPath,
|
secretPath,
|
||||||
policyId
|
policyId
|
||||||
}: {
|
}: {
|
||||||
envId: string;
|
envId?: string;
|
||||||
|
envIds?: string[];
|
||||||
secretPath: string;
|
secretPath: string;
|
||||||
policyId?: string;
|
policyId?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const policy = await accessApprovalPolicyDAL
|
if (!envId && !envIds) {
|
||||||
.findOne({
|
throw new BadRequestError({ message: "Must provide either envId or envIds" });
|
||||||
envId,
|
}
|
||||||
secretPath,
|
const policy = await accessApprovalPolicyDAL.findPolicyByEnvIdAndSecretPath({
|
||||||
deletedAt: null
|
secretPath,
|
||||||
})
|
envIds: envId ? [envId] : (envIds as string[])
|
||||||
.catch(() => null);
|
});
|
||||||
|
|
||||||
return policyId ? policy && policy.id !== policyId : Boolean(policy);
|
return policyId ? policy && policy.id !== policyId : Boolean(policy);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,6 +97,7 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
bypassers,
|
bypassers,
|
||||||
projectSlug,
|
projectSlug,
|
||||||
environment,
|
environment,
|
||||||
|
environments,
|
||||||
enforcementLevel,
|
enforcementLevel,
|
||||||
allowedSelfApprovals,
|
allowedSelfApprovals,
|
||||||
approvalsRequired
|
approvalsRequired
|
||||||
@@ -116,20 +122,31 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionActions.Create,
|
ProjectPermissionActions.Create,
|
||||||
ProjectPermissionSub.SecretApproval
|
ProjectPermissionSub.SecretApproval
|
||||||
);
|
);
|
||||||
const env = await projectEnvDAL.findOne({ slug: environment, projectId: project.id });
|
const mergedEnvs = (environment ? [environment] : environments) || [];
|
||||||
if (!env) throw new NotFoundError({ message: `Environment with slug '${environment}' not found` });
|
if (mergedEnvs.length === 0) {
|
||||||
|
throw new BadRequestError({ message: "Must provide either environment or environments" });
|
||||||
|
}
|
||||||
|
const envs = await projectEnvDAL.find({ $in: { slug: mergedEnvs }, projectId: project.id });
|
||||||
|
if (!envs.length || envs.length !== mergedEnvs.length) {
|
||||||
|
const notFoundEnvs = mergedEnvs.filter((env) => !envs.find((el) => el.slug === env));
|
||||||
|
throw new NotFoundError({ message: `One or more environments not found: ${notFoundEnvs.join(", ")}` });
|
||||||
|
}
|
||||||
|
|
||||||
if (await $policyExists({ envId: env.id, secretPath })) {
|
for (const env of envs) {
|
||||||
throw new BadRequestError({
|
// eslint-disable-next-line no-await-in-loop
|
||||||
message: `A policy for secret path '${secretPath}' already exists in environment '${environment}'`
|
if (await $policyExists({ envId: env.id, secretPath })) {
|
||||||
});
|
throw new BadRequestError({
|
||||||
|
message: `A policy for secret path '${secretPath}' already exists in environment '${env.slug}'`
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let approverUserIds = userApprovers;
|
let approverUserIds = userApprovers;
|
||||||
@@ -197,7 +214,7 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
const accessApproval = await accessApprovalPolicyDAL.transaction(async (tx) => {
|
const accessApproval = await accessApprovalPolicyDAL.transaction(async (tx) => {
|
||||||
const doc = await accessApprovalPolicyDAL.create(
|
const doc = await accessApprovalPolicyDAL.create(
|
||||||
{
|
{
|
||||||
envId: env.id,
|
envId: envs[0].id,
|
||||||
approvals,
|
approvals,
|
||||||
secretPath,
|
secretPath,
|
||||||
name,
|
name,
|
||||||
@@ -206,6 +223,10 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
},
|
},
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
await accessApprovalPolicyEnvironmentDAL.insertMany(
|
||||||
|
envs.map((el) => ({ policyId: doc.id, envId: el.id })),
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
|
||||||
if (approverUserIds.length) {
|
if (approverUserIds.length) {
|
||||||
await accessApprovalPolicyApproverDAL.insertMany(
|
await accessApprovalPolicyApproverDAL.insertMany(
|
||||||
@@ -258,7 +279,7 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
return doc;
|
return doc;
|
||||||
});
|
});
|
||||||
|
|
||||||
return { ...accessApproval, environment: env, projectId: project.id };
|
return { ...accessApproval, environments: envs, projectId: project.id, environment: envs[0] };
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAccessApprovalPolicyByProjectSlug: TAccessApprovalPolicyServiceFactory["getAccessApprovalPolicyByProjectSlug"] =
|
const getAccessApprovalPolicyByProjectSlug: TAccessApprovalPolicyServiceFactory["getAccessApprovalPolicyByProjectSlug"] =
|
||||||
@@ -272,11 +293,15 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const accessApprovalPolicies = await accessApprovalPolicyDAL.find({ projectId: project.id, deletedAt: null });
|
const accessApprovalPolicies = await accessApprovalPolicyDAL.find({ projectId: project.id, deletedAt: null });
|
||||||
return accessApprovalPolicies;
|
return accessApprovalPolicies.map((policy) => ({
|
||||||
|
...policy,
|
||||||
|
environment: policy.environments[0]
|
||||||
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateAccessApprovalPolicy: TAccessApprovalPolicyServiceFactory["updateAccessApprovalPolicy"] = async ({
|
const updateAccessApprovalPolicy: TAccessApprovalPolicyServiceFactory["updateAccessApprovalPolicy"] = async ({
|
||||||
@@ -292,7 +317,8 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
approvals,
|
approvals,
|
||||||
enforcementLevel,
|
enforcementLevel,
|
||||||
allowedSelfApprovals,
|
allowedSelfApprovals,
|
||||||
approvalsRequired
|
approvalsRequired,
|
||||||
|
environments
|
||||||
}: TUpdateAccessApprovalPolicy) => {
|
}: TUpdateAccessApprovalPolicy) => {
|
||||||
const groupApprovers = approvers.filter((approver) => approver.type === ApproverType.Group);
|
const groupApprovers = approvers.filter((approver) => approver.type === ApproverType.Group);
|
||||||
|
|
||||||
@@ -320,16 +346,27 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
throw new BadRequestError({ message: "Approvals cannot be greater than approvers" });
|
throw new BadRequestError({ message: "Approvals cannot be greater than approvers" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let envs = accessApprovalPolicy.environments;
|
||||||
if (
|
if (
|
||||||
await $policyExists({
|
environments &&
|
||||||
envId: accessApprovalPolicy.envId,
|
(environments.length !== envs.length || environments.some((env) => !envs.find((el) => el.slug === env)))
|
||||||
secretPath: secretPath || accessApprovalPolicy.secretPath,
|
|
||||||
policyId: accessApprovalPolicy.id
|
|
||||||
})
|
|
||||||
) {
|
) {
|
||||||
throw new BadRequestError({
|
envs = await projectEnvDAL.find({ $in: { slug: environments }, projectId: accessApprovalPolicy.projectId });
|
||||||
message: `A policy for secret path '${secretPath}' already exists in environment '${accessApprovalPolicy.environment.slug}'`
|
}
|
||||||
});
|
|
||||||
|
for (const env of envs) {
|
||||||
|
if (
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await $policyExists({
|
||||||
|
envId: env.id,
|
||||||
|
secretPath: secretPath || accessApprovalPolicy.secretPath,
|
||||||
|
policyId: accessApprovalPolicy.id
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `A policy for secret path '${secretPath || accessApprovalPolicy.secretPath}' already exists in environment '${env.slug}'`
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { permission } = await permissionService.getProjectPermission({
|
const { permission } = await permissionService.getProjectPermission({
|
||||||
@@ -337,7 +374,8 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: accessApprovalPolicy.projectId,
|
projectId: accessApprovalPolicy.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SecretApproval);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SecretApproval);
|
||||||
@@ -484,6 +522,14 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (environments) {
|
||||||
|
await accessApprovalPolicyEnvironmentDAL.delete({ policyId: doc.id }, tx);
|
||||||
|
await accessApprovalPolicyEnvironmentDAL.insertMany(
|
||||||
|
envs.map((env) => ({ policyId: doc.id, envId: env.id })),
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await accessApprovalPolicyBypasserDAL.delete({ policyId: doc.id }, tx);
|
await accessApprovalPolicyBypasserDAL.delete({ policyId: doc.id }, tx);
|
||||||
|
|
||||||
if (bypasserUserIds.length) {
|
if (bypasserUserIds.length) {
|
||||||
@@ -513,7 +559,8 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...updatedPolicy,
|
...updatedPolicy,
|
||||||
environment: accessApprovalPolicy.environment,
|
environments: accessApprovalPolicy.environments,
|
||||||
|
environment: accessApprovalPolicy.environments[0],
|
||||||
projectId: accessApprovalPolicy.projectId
|
projectId: accessApprovalPolicy.projectId
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -533,7 +580,8 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: policy.projectId,
|
projectId: policy.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionActions.Delete,
|
ProjectPermissionActions.Delete,
|
||||||
@@ -563,7 +611,10 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return policy;
|
return {
|
||||||
|
...policy,
|
||||||
|
environment: policy.environments[0]
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAccessPolicyCountByEnvSlug: TAccessApprovalPolicyServiceFactory["getAccessPolicyCountByEnvSlug"] = async ({
|
const getAccessPolicyCountByEnvSlug: TAccessApprovalPolicyServiceFactory["getAccessPolicyCountByEnvSlug"] = async ({
|
||||||
@@ -583,7 +634,8 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
if (!membership) {
|
if (!membership) {
|
||||||
throw new ForbiddenRequestError({ message: "You are not a member of this project" });
|
throw new ForbiddenRequestError({ message: "You are not a member of this project" });
|
||||||
@@ -592,11 +644,13 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
const environment = await projectEnvDAL.findOne({ projectId: project.id, slug: envSlug });
|
const environment = await projectEnvDAL.findOne({ projectId: project.id, slug: envSlug });
|
||||||
if (!environment) throw new NotFoundError({ message: `Environment with slug '${envSlug}' not found` });
|
if (!environment) throw new NotFoundError({ message: `Environment with slug '${envSlug}' not found` });
|
||||||
|
|
||||||
const policies = await accessApprovalPolicyDAL.find({
|
const policies = await accessApprovalPolicyDAL.find(
|
||||||
envId: environment.id,
|
{
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
deletedAt: null
|
deletedAt: null
|
||||||
});
|
},
|
||||||
|
{ envId: environment.id }
|
||||||
|
);
|
||||||
if (!policies) throw new NotFoundError({ message: `No policies found in environment with slug '${envSlug}'` });
|
if (!policies) throw new NotFoundError({ message: `No policies found in environment with slug '${envSlug}'` });
|
||||||
|
|
||||||
return { count: policies.length };
|
return { count: policies.length };
|
||||||
@@ -622,12 +676,16 @@ export const accessApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: policy.projectId,
|
projectId: policy.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval);
|
||||||
|
|
||||||
return policy;
|
return {
|
||||||
|
...policy,
|
||||||
|
environment: policy.environments[0]
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@@ -26,7 +26,8 @@ export enum BypasserType {
|
|||||||
export type TCreateAccessApprovalPolicy = {
|
export type TCreateAccessApprovalPolicy = {
|
||||||
approvals: number;
|
approvals: number;
|
||||||
secretPath: string;
|
secretPath: string;
|
||||||
environment: string;
|
environment?: string;
|
||||||
|
environments?: string[];
|
||||||
approvers: (
|
approvers: (
|
||||||
| { type: ApproverType.Group; id: string; sequence?: number }
|
| { type: ApproverType.Group; id: string; sequence?: number }
|
||||||
| { type: ApproverType.User; id?: string; username?: string; sequence?: number }
|
| { type: ApproverType.User; id?: string; username?: string; sequence?: number }
|
||||||
@@ -58,6 +59,7 @@ export type TUpdateAccessApprovalPolicy = {
|
|||||||
enforcementLevel?: EnforcementLevel;
|
enforcementLevel?: EnforcementLevel;
|
||||||
allowedSelfApprovals: boolean;
|
allowedSelfApprovals: boolean;
|
||||||
approvalsRequired?: { numberOfApprovals: number; stepNumber: number }[];
|
approvalsRequired?: { numberOfApprovals: number; stepNumber: number }[];
|
||||||
|
environments?: string[];
|
||||||
} & Omit<TProjectPermission, "projectId">;
|
} & Omit<TProjectPermission, "projectId">;
|
||||||
|
|
||||||
export type TDeleteAccessApprovalPolicy = {
|
export type TDeleteAccessApprovalPolicy = {
|
||||||
@@ -113,6 +115,15 @@ export interface TAccessApprovalPolicyServiceFactory {
|
|||||||
slug: string;
|
slug: string;
|
||||||
position: number;
|
position: number;
|
||||||
};
|
};
|
||||||
|
environments: {
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
createdAt: Date;
|
||||||
|
updatedAt: Date;
|
||||||
|
projectId: string;
|
||||||
|
slug: string;
|
||||||
|
position: number;
|
||||||
|
}[];
|
||||||
projectId: string;
|
projectId: string;
|
||||||
name: string;
|
name: string;
|
||||||
id: string;
|
id: string;
|
||||||
@@ -153,6 +164,11 @@ export interface TAccessApprovalPolicyServiceFactory {
|
|||||||
name: string;
|
name: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
};
|
};
|
||||||
|
environments: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
}[];
|
||||||
projectId: string;
|
projectId: string;
|
||||||
}>;
|
}>;
|
||||||
updateAccessApprovalPolicy: ({
|
updateAccessApprovalPolicy: ({
|
||||||
@@ -168,13 +184,19 @@ export interface TAccessApprovalPolicyServiceFactory {
|
|||||||
approvals,
|
approvals,
|
||||||
enforcementLevel,
|
enforcementLevel,
|
||||||
allowedSelfApprovals,
|
allowedSelfApprovals,
|
||||||
approvalsRequired
|
approvalsRequired,
|
||||||
|
environments
|
||||||
}: TUpdateAccessApprovalPolicy) => Promise<{
|
}: TUpdateAccessApprovalPolicy) => Promise<{
|
||||||
environment: {
|
environment: {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
};
|
};
|
||||||
|
environments: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
}[];
|
||||||
projectId: string;
|
projectId: string;
|
||||||
name: string;
|
name: string;
|
||||||
id: string;
|
id: string;
|
||||||
@@ -225,6 +247,11 @@ export interface TAccessApprovalPolicyServiceFactory {
|
|||||||
name: string;
|
name: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
};
|
};
|
||||||
|
environments: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
}[];
|
||||||
projectId: string;
|
projectId: string;
|
||||||
bypassers: (
|
bypassers: (
|
||||||
| {
|
| {
|
||||||
@@ -276,6 +303,11 @@ export interface TAccessApprovalPolicyServiceFactory {
|
|||||||
name: string;
|
name: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
};
|
};
|
||||||
|
environments: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
}[];
|
||||||
projectId: string;
|
projectId: string;
|
||||||
bypassers: (
|
bypassers: (
|
||||||
| {
|
| {
|
||||||
|
@@ -65,7 +65,7 @@ export interface TAccessApprovalRequestDALFactory extends Omit<TOrmify<TableName
|
|||||||
deletedAt: Date | null | undefined;
|
deletedAt: Date | null | undefined;
|
||||||
};
|
};
|
||||||
projectId: string;
|
projectId: string;
|
||||||
environment: string;
|
environments: string[];
|
||||||
requestedByUser: {
|
requestedByUser: {
|
||||||
userId: string;
|
userId: string;
|
||||||
email: string | null | undefined;
|
email: string | null | undefined;
|
||||||
@@ -515,7 +515,17 @@ export const accessApprovalRequestDALFactory = (db: TDbClient): TAccessApprovalR
|
|||||||
`accessApprovalReviewerUser.id`
|
`accessApprovalReviewerUser.id`
|
||||||
)
|
)
|
||||||
|
|
||||||
.leftJoin(TableName.Environment, `${TableName.AccessApprovalPolicy}.envId`, `${TableName.Environment}.id`)
|
.leftJoin(
|
||||||
|
TableName.AccessApprovalPolicyEnvironment,
|
||||||
|
`${TableName.AccessApprovalPolicy}.id`,
|
||||||
|
`${TableName.AccessApprovalPolicyEnvironment}.policyId`
|
||||||
|
)
|
||||||
|
|
||||||
|
.leftJoin(
|
||||||
|
TableName.Environment,
|
||||||
|
`${TableName.AccessApprovalPolicyEnvironment}.envId`,
|
||||||
|
`${TableName.Environment}.id`
|
||||||
|
)
|
||||||
.select(selectAllTableCols(TableName.AccessApprovalRequest))
|
.select(selectAllTableCols(TableName.AccessApprovalRequest))
|
||||||
.select(
|
.select(
|
||||||
tx.ref("approverUserId").withSchema(TableName.AccessApprovalPolicyApprover),
|
tx.ref("approverUserId").withSchema(TableName.AccessApprovalPolicyApprover),
|
||||||
@@ -683,6 +693,11 @@ export const accessApprovalRequestDALFactory = (db: TDbClient): TAccessApprovalR
|
|||||||
lastName,
|
lastName,
|
||||||
username
|
username
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "environment",
|
||||||
|
label: "environments" as const,
|
||||||
|
mapper: ({ environment }) => environment
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import slugify from "@sindresorhus/slugify";
|
import slugify from "@sindresorhus/slugify";
|
||||||
import msFn from "ms";
|
import msFn from "ms";
|
||||||
|
|
||||||
import { ProjectMembershipRole } from "@app/db/schemas";
|
import { ActionProjectType, ProjectMembershipRole } from "@app/db/schemas";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { groupBy } from "@app/lib/fn";
|
import { groupBy } from "@app/lib/fn";
|
||||||
@@ -86,6 +86,25 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
projectMicrosoftTeamsConfigDAL,
|
projectMicrosoftTeamsConfigDAL,
|
||||||
projectSlackConfigDAL
|
projectSlackConfigDAL
|
||||||
}: TSecretApprovalRequestServiceFactoryDep): TAccessApprovalRequestServiceFactory => {
|
}: TSecretApprovalRequestServiceFactoryDep): TAccessApprovalRequestServiceFactory => {
|
||||||
|
const $getEnvironmentFromPermissions = (permissions: unknown): string | null => {
|
||||||
|
if (!Array.isArray(permissions) || permissions.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstPermission = permissions[0] as unknown[];
|
||||||
|
if (!Array.isArray(firstPermission) || firstPermission.length < 3) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const metadata = firstPermission[2] as Record<string, unknown>;
|
||||||
|
if (typeof metadata === "object" && metadata !== null && "environment" in metadata) {
|
||||||
|
const env = metadata.environment;
|
||||||
|
return typeof env === "string" ? env : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
const createAccessApprovalRequest: TAccessApprovalRequestServiceFactory["createAccessApprovalRequest"] = async ({
|
const createAccessApprovalRequest: TAccessApprovalRequestServiceFactory["createAccessApprovalRequest"] = async ({
|
||||||
isTemporary,
|
isTemporary,
|
||||||
temporaryRange,
|
temporaryRange,
|
||||||
@@ -107,7 +126,8 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
if (!membership) {
|
if (!membership) {
|
||||||
throw new ForbiddenRequestError({ message: "You are not a member of this project" });
|
throw new ForbiddenRequestError({ message: "You are not a member of this project" });
|
||||||
@@ -216,7 +236,7 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const requesterFullName = `${requestedByUser.firstName} ${requestedByUser.lastName}`;
|
const requesterFullName = `${requestedByUser.firstName} ${requestedByUser.lastName}`;
|
||||||
const approvalUrl = `${cfg.SITE_URL}/projects/${project.id}/secret-manager/approval`;
|
const approvalUrl = `${cfg.SITE_URL}/projects/secret-management/${project.id}/approval`;
|
||||||
|
|
||||||
await triggerWorkflowIntegrationNotification({
|
await triggerWorkflowIntegrationNotification({
|
||||||
input: {
|
input: {
|
||||||
@@ -289,7 +309,8 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
if (!membership) {
|
if (!membership) {
|
||||||
throw new ForbiddenRequestError({ message: "You are not a member of this project" });
|
throw new ForbiddenRequestError({ message: "You are not a member of this project" });
|
||||||
@@ -306,6 +327,15 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
requests = requests.filter((request) => request.environment === envSlug);
|
requests = requests.filter((request) => request.environment === envSlug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
requests = requests.map((request) => {
|
||||||
|
const permissionEnvironment = $getEnvironmentFromPermissions(request.permissions);
|
||||||
|
|
||||||
|
if (permissionEnvironment) {
|
||||||
|
request.environmentName = permissionEnvironment;
|
||||||
|
}
|
||||||
|
return request;
|
||||||
|
});
|
||||||
|
|
||||||
return { requests };
|
return { requests };
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -323,19 +353,34 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
throw new NotFoundError({ message: `Secret approval request with ID '${requestId}' not found` });
|
throw new NotFoundError({ message: `Secret approval request with ID '${requestId}' not found` });
|
||||||
}
|
}
|
||||||
|
|
||||||
const { policy, environment } = accessApprovalRequest;
|
const { policy, environments, permissions } = accessApprovalRequest;
|
||||||
if (policy.deletedAt) {
|
if (policy.deletedAt) {
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
message: "The policy associated with this access request has been deleted."
|
message: "The policy associated with this access request has been deleted."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const permissionEnvironment = $getEnvironmentFromPermissions(permissions);
|
||||||
|
if (
|
||||||
|
!permissionEnvironment ||
|
||||||
|
(!environments.includes(permissionEnvironment) && status === ApprovalStatus.APPROVED)
|
||||||
|
) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `The original policy ${policy.name} is not attached to environment '${permissionEnvironment}'.`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const environment = await projectEnvDAL.findOne({
|
||||||
|
projectId: accessApprovalRequest.projectId,
|
||||||
|
slug: permissionEnvironment
|
||||||
|
});
|
||||||
|
|
||||||
const { membership, hasRole } = await permissionService.getProjectPermission({
|
const { membership, hasRole } = await permissionService.getProjectPermission({
|
||||||
actor,
|
actor,
|
||||||
actorId,
|
actorId,
|
||||||
projectId: accessApprovalRequest.projectId,
|
projectId: accessApprovalRequest.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!membership) {
|
if (!membership) {
|
||||||
@@ -550,8 +595,8 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
requesterEmail: actingUser.email,
|
requesterEmail: actingUser.email,
|
||||||
bypassReason: bypassReason || "No reason provided",
|
bypassReason: bypassReason || "No reason provided",
|
||||||
secretPath: policy.secretPath || "/",
|
secretPath: policy.secretPath || "/",
|
||||||
environment,
|
environment: environment?.name || permissionEnvironment,
|
||||||
approvalUrl: `${cfg.SITE_URL}/projects/${project.id}/secret-manager/approval`,
|
approvalUrl: `${cfg.SITE_URL}/projects/secret-management/${project.id}/approval`,
|
||||||
requestType: "access"
|
requestType: "access"
|
||||||
},
|
},
|
||||||
template: SmtpTemplates.AccessSecretRequestBypassed
|
template: SmtpTemplates.AccessSecretRequestBypassed
|
||||||
@@ -582,7 +627,8 @@ export const accessApprovalRequestServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
if (!membership) {
|
if (!membership) {
|
||||||
throw new ForbiddenRequestError({ message: "You are not a member of this project" });
|
throw new ForbiddenRequestError({ message: "You are not a member of this project" });
|
||||||
|
@@ -45,7 +45,10 @@ export const ValidateOracleDBConnectionCredentialsSchema = z.discriminatedUnion(
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
export const CreateOracleDBConnectionSchema = ValidateOracleDBConnectionCredentialsSchema.and(
|
export const CreateOracleDBConnectionSchema = ValidateOracleDBConnectionCredentialsSchema.and(
|
||||||
GenericCreateAppConnectionFieldsSchema(AppConnection.OracleDB, { supportsPlatformManagedCredentials: true })
|
GenericCreateAppConnectionFieldsSchema(AppConnection.OracleDB, {
|
||||||
|
supportsPlatformManagedCredentials: true,
|
||||||
|
supportsGateways: true
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
export const UpdateOracleDBConnectionSchema = z
|
export const UpdateOracleDBConnectionSchema = z
|
||||||
@@ -54,7 +57,12 @@ export const UpdateOracleDBConnectionSchema = z
|
|||||||
AppConnections.UPDATE(AppConnection.OracleDB).credentials
|
AppConnections.UPDATE(AppConnection.OracleDB).credentials
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.and(GenericUpdateAppConnectionFieldsSchema(AppConnection.OracleDB, { supportsPlatformManagedCredentials: true }));
|
.and(
|
||||||
|
GenericUpdateAppConnectionFieldsSchema(AppConnection.OracleDB, {
|
||||||
|
supportsPlatformManagedCredentials: true,
|
||||||
|
supportsGateways: true
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
export const OracleDBConnectionListItemSchema = z.object({
|
export const OracleDBConnectionListItemSchema = z.object({
|
||||||
name: z.literal("OracleDB"),
|
name: z.literal("OracleDB"),
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { crypto } from "@app/lib/crypto/cryptography";
|
import { crypto } from "@app/lib/crypto/cryptography";
|
||||||
import { ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
import { ForbiddenRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
@@ -37,7 +38,8 @@ export const assumePrivilegeServiceFactory = ({
|
|||||||
actorId: actorPermissionDetails.id,
|
actorId: actorPermissionDetails.id,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod: actorPermissionDetails.authMethod,
|
actorAuthMethod: actorPermissionDetails.authMethod,
|
||||||
actorOrgId: actorPermissionDetails.orgId
|
actorOrgId: actorPermissionDetails.orgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
if (targetActorType === ActorType.USER) {
|
if (targetActorType === ActorType.USER) {
|
||||||
@@ -58,7 +60,8 @@ export const assumePrivilegeServiceFactory = ({
|
|||||||
actorId: targetActorId,
|
actorId: targetActorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod: actorPermissionDetails.authMethod,
|
actorAuthMethod: actorPermissionDetails.authMethod,
|
||||||
actorOrgId: actorPermissionDetails.orgId
|
actorOrgId: actorPermissionDetails.orgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
const appCfg = getConfig();
|
const appCfg = getConfig();
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
import { requestContext } from "@fastify/request-context";
|
import { requestContext } from "@fastify/request-context";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { BadRequestError } from "@app/lib/errors";
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
import { ActorType } from "@app/services/auth/auth-type";
|
import { ActorType } from "@app/services/auth/auth-type";
|
||||||
@@ -37,7 +38,8 @@ export const auditLogServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: filter.projectId,
|
projectId: filter.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.AuditLogs);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.AuditLogs);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -449,6 +449,7 @@ export enum EventType {
|
|||||||
PIT_REVERT_COMMIT = "pit-revert-commit",
|
PIT_REVERT_COMMIT = "pit-revert-commit",
|
||||||
PIT_GET_FOLDER_STATE = "pit-get-folder-state",
|
PIT_GET_FOLDER_STATE = "pit-get-folder-state",
|
||||||
PIT_COMPARE_FOLDER_STATES = "pit-compare-folder-states",
|
PIT_COMPARE_FOLDER_STATES = "pit-compare-folder-states",
|
||||||
|
PIT_PROCESS_NEW_COMMIT_RAW = "pit-process-new-commit-raw",
|
||||||
SECRET_SCANNING_DATA_SOURCE_LIST = "secret-scanning-data-source-list",
|
SECRET_SCANNING_DATA_SOURCE_LIST = "secret-scanning-data-source-list",
|
||||||
SECRET_SCANNING_DATA_SOURCE_CREATE = "secret-scanning-data-source-create",
|
SECRET_SCANNING_DATA_SOURCE_CREATE = "secret-scanning-data-source-create",
|
||||||
SECRET_SCANNING_DATA_SOURCE_UPDATE = "secret-scanning-data-source-update",
|
SECRET_SCANNING_DATA_SOURCE_UPDATE = "secret-scanning-data-source-update",
|
||||||
@@ -467,7 +468,11 @@ export enum EventType {
|
|||||||
|
|
||||||
CREATE_PROJECT = "create-project",
|
CREATE_PROJECT = "create-project",
|
||||||
UPDATE_PROJECT = "update-project",
|
UPDATE_PROJECT = "update-project",
|
||||||
DELETE_PROJECT = "delete-project"
|
DELETE_PROJECT = "delete-project",
|
||||||
|
|
||||||
|
CREATE_SECRET_REMINDER = "create-secret-reminder",
|
||||||
|
GET_SECRET_REMINDER = "get-secret-reminder",
|
||||||
|
DELETE_SECRET_REMINDER = "delete-secret-reminder"
|
||||||
}
|
}
|
||||||
|
|
||||||
export const filterableSecretEvents: EventType[] = [
|
export const filterableSecretEvents: EventType[] = [
|
||||||
@@ -1546,8 +1551,9 @@ interface UpdateFolderEvent {
|
|||||||
metadata: {
|
metadata: {
|
||||||
environment: string;
|
environment: string;
|
||||||
folderId: string;
|
folderId: string;
|
||||||
oldFolderName: string;
|
oldFolderName?: string;
|
||||||
newFolderName: string;
|
newFolderName: string;
|
||||||
|
newFolderDescription?: string;
|
||||||
folderPath: string;
|
folderPath: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -3222,6 +3228,18 @@ interface PitCompareFolderStatesEvent {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PitProcessNewCommitRawEvent {
|
||||||
|
type: EventType.PIT_PROCESS_NEW_COMMIT_RAW;
|
||||||
|
metadata: {
|
||||||
|
projectId: string;
|
||||||
|
environment: string;
|
||||||
|
secretPath: string;
|
||||||
|
message: string;
|
||||||
|
approvalId?: string;
|
||||||
|
commitId?: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
interface SecretScanningDataSourceListEvent {
|
interface SecretScanningDataSourceListEvent {
|
||||||
type: EventType.SECRET_SCANNING_DATA_SOURCE_LIST;
|
type: EventType.SECRET_SCANNING_DATA_SOURCE_LIST;
|
||||||
metadata: {
|
metadata: {
|
||||||
@@ -3312,6 +3330,31 @@ interface SecretScanningConfigUpdateEvent {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SecretReminderCreateEvent {
|
||||||
|
type: EventType.CREATE_SECRET_REMINDER;
|
||||||
|
metadata: {
|
||||||
|
secretId: string;
|
||||||
|
message?: string | null;
|
||||||
|
repeatDays?: number | null;
|
||||||
|
nextReminderDate?: string | null;
|
||||||
|
recipients?: string[] | null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SecretReminderGetEvent {
|
||||||
|
type: EventType.GET_SECRET_REMINDER;
|
||||||
|
metadata: {
|
||||||
|
secretId: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SecretReminderDeleteEvent {
|
||||||
|
type: EventType.DELETE_SECRET_REMINDER;
|
||||||
|
metadata: {
|
||||||
|
secretId: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
interface SecretScanningConfigReadEvent {
|
interface SecretScanningConfigReadEvent {
|
||||||
type: EventType.SECRET_SCANNING_CONFIG_GET;
|
type: EventType.SECRET_SCANNING_CONFIG_GET;
|
||||||
metadata?: Record<string, never>; // not needed, based off projectId
|
metadata?: Record<string, never>; // not needed, based off projectId
|
||||||
@@ -3658,6 +3701,7 @@ export type Event =
|
|||||||
| PitRevertCommitEvent
|
| PitRevertCommitEvent
|
||||||
| PitCompareFolderStatesEvent
|
| PitCompareFolderStatesEvent
|
||||||
| PitGetFolderStateEvent
|
| PitGetFolderStateEvent
|
||||||
|
| PitProcessNewCommitRawEvent
|
||||||
| SecretScanningDataSourceListEvent
|
| SecretScanningDataSourceListEvent
|
||||||
| SecretScanningDataSourceGetEvent
|
| SecretScanningDataSourceGetEvent
|
||||||
| SecretScanningDataSourceCreateEvent
|
| SecretScanningDataSourceCreateEvent
|
||||||
@@ -3674,4 +3718,7 @@ export type Event =
|
|||||||
| OrgUpdateEvent
|
| OrgUpdateEvent
|
||||||
| ProjectCreateEvent
|
| ProjectCreateEvent
|
||||||
| ProjectUpdateEvent
|
| ProjectUpdateEvent
|
||||||
| ProjectDeleteEvent;
|
| ProjectDeleteEvent
|
||||||
|
| SecretReminderCreateEvent
|
||||||
|
| SecretReminderGetEvent
|
||||||
|
| SecretReminderDeleteEvent;
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
import * as x509 from "@peculiar/x509";
|
import * as x509 from "@peculiar/x509";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { TCertificateAuthorityCrlDALFactory } from "@app/ee/services/certificate-authority-crl/certificate-authority-crl-dal";
|
import { TCertificateAuthorityCrlDALFactory } from "@app/ee/services/certificate-authority-crl/certificate-authority-crl-dal";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
@@ -77,7 +78,8 @@ export const certificateAuthorityCrlServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: ca.projectId,
|
projectId: ca.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.CertificateManager
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { ForbiddenError, subject } from "@casl/ability";
|
import { ForbiddenError, subject } from "@casl/ability";
|
||||||
import RE2 from "re2";
|
import RE2 from "re2";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
import {
|
import {
|
||||||
@@ -84,7 +85,8 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const plan = await licenseService.getPlan(actorOrgId);
|
const plan = await licenseService.getPlan(actorOrgId);
|
||||||
@@ -200,7 +202,8 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
||||||
@@ -297,7 +300,8 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
|
||||||
@@ -385,7 +389,8 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
||||||
@@ -432,7 +437,8 @@ export const dynamicSecretLeaseServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { ForbiddenError, subject } from "@casl/ability";
|
import { ForbiddenError, subject } from "@casl/ability";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
import {
|
import {
|
||||||
@@ -78,7 +79,8 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -207,7 +209,8 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const plan = await licenseService.getPlan(actorOrgId);
|
const plan = await licenseService.getPlan(actorOrgId);
|
||||||
@@ -358,7 +361,8 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
||||||
@@ -423,7 +427,8 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
||||||
@@ -487,7 +492,8 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
// verify user has access to each env in request
|
// verify user has access to each env in request
|
||||||
@@ -530,7 +536,8 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionDynamicSecretActions.ReadRootCredential,
|
ProjectPermissionDynamicSecretActions.ReadRootCredential,
|
||||||
@@ -578,7 +585,8 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
const folder = await folderDAL.findBySecretPath(projectId, environmentSlug, path);
|
||||||
@@ -615,7 +623,8 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const userAccessibleFolderMappings = folderMappings.filter(({ path, environment }) =>
|
const userAccessibleFolderMappings = folderMappings.filter(({ path, environment }) =>
|
||||||
@@ -659,7 +668,8 @@ export const dynamicSecretServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const folders = await folderDAL.findBySecretPathMultiEnv(projectId, environmentSlugs, path);
|
const folders = await folderDAL.findBySecretPathMultiEnv(projectId, environmentSlugs, path);
|
||||||
|
@@ -566,6 +566,14 @@ export const gatewayServiceFactory = ({
|
|||||||
if (!gateway) throw new NotFoundError({ message: `Gateway with ID ${gatewayId} not found.` });
|
if (!gateway) throw new NotFoundError({ message: `Gateway with ID ${gatewayId} not found.` });
|
||||||
|
|
||||||
const orgGatewayConfig = await orgGatewayConfigDAL.findById(gateway.orgGatewayRootCaId);
|
const orgGatewayConfig = await orgGatewayConfigDAL.findById(gateway.orgGatewayRootCaId);
|
||||||
|
|
||||||
|
const orgLicensePlan = await licenseService.getPlan(orgGatewayConfig.orgId);
|
||||||
|
if (!orgLicensePlan.gateway) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: "Please upgrade your instance to Infisical's Enterprise plan to use gateways."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const { decryptor: orgKmsDecryptor } = await kmsService.createCipherPairWithDataKey({
|
const { decryptor: orgKmsDecryptor } = await kmsService.createCipherPairWithDataKey({
|
||||||
type: KmsDataKey.Organization,
|
type: KmsDataKey.Organization,
|
||||||
orgId: orgGatewayConfig.orgId
|
orgId: orgGatewayConfig.orgId
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { ForbiddenError, subject } from "@casl/ability";
|
import { ForbiddenError, subject } from "@casl/ability";
|
||||||
import { packRules } from "@casl/ability/extra";
|
import { packRules } from "@casl/ability/extra";
|
||||||
|
|
||||||
import { TableName } from "@app/db/schemas";
|
import { ActionProjectType, TableName } from "@app/db/schemas";
|
||||||
import { BadRequestError, NotFoundError, PermissionBoundaryError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError, PermissionBoundaryError } from "@app/lib/errors";
|
||||||
import { ms } from "@app/lib/ms";
|
import { ms } from "@app/lib/ms";
|
||||||
import { validateHandlebarTemplate } from "@app/lib/template/validate-handlebars";
|
import { validateHandlebarTemplate } from "@app/lib/template/validate-handlebars";
|
||||||
@@ -61,7 +61,8 @@ export const identityProjectAdditionalPrivilegeV2ServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionIdentityActions.Edit,
|
ProjectPermissionIdentityActions.Edit,
|
||||||
@@ -72,7 +73,8 @@ export const identityProjectAdditionalPrivilegeV2ServiceFactory = ({
|
|||||||
actorId: identityId,
|
actorId: identityId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
// we need to validate that the privilege given is not higher than the assigning users permission
|
// we need to validate that the privilege given is not higher than the assigning users permission
|
||||||
@@ -158,7 +160,8 @@ export const identityProjectAdditionalPrivilegeV2ServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionIdentityActions.Edit,
|
ProjectPermissionIdentityActions.Edit,
|
||||||
@@ -169,7 +172,8 @@ export const identityProjectAdditionalPrivilegeV2ServiceFactory = ({
|
|||||||
actorId: identityProjectMembership.identityId,
|
actorId: identityProjectMembership.identityId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
// we need to validate that the privilege given is not higher than the assigning users permission
|
// we need to validate that the privilege given is not higher than the assigning users permission
|
||||||
@@ -256,7 +260,8 @@ export const identityProjectAdditionalPrivilegeV2ServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionIdentityActions.Edit,
|
ProjectPermissionIdentityActions.Edit,
|
||||||
@@ -267,7 +272,8 @@ export const identityProjectAdditionalPrivilegeV2ServiceFactory = ({
|
|||||||
actorId: identityProjectMembership.identityId,
|
actorId: identityProjectMembership.identityId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
const permissionBoundary = validatePrivilegeChangeOperation(
|
const permissionBoundary = validatePrivilegeChangeOperation(
|
||||||
membership.shouldUseNewPrivilegeSystem,
|
membership.shouldUseNewPrivilegeSystem,
|
||||||
@@ -315,7 +321,8 @@ export const identityProjectAdditionalPrivilegeV2ServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionIdentityActions.Read,
|
ProjectPermissionIdentityActions.Read,
|
||||||
@@ -349,7 +356,8 @@ export const identityProjectAdditionalPrivilegeV2ServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionIdentityActions.Read,
|
ProjectPermissionIdentityActions.Read,
|
||||||
@@ -384,7 +392,8 @@ export const identityProjectAdditionalPrivilegeV2ServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionIdentityActions.Read,
|
ProjectPermissionIdentityActions.Read,
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { ForbiddenError, MongoAbility, RawRuleOf, subject } from "@casl/ability";
|
import { ForbiddenError, MongoAbility, RawRuleOf, subject } from "@casl/ability";
|
||||||
import { PackRule, packRules, unpackRules } from "@casl/ability/extra";
|
import { PackRule, packRules, unpackRules } from "@casl/ability/extra";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { BadRequestError, NotFoundError, PermissionBoundaryError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError, PermissionBoundaryError } from "@app/lib/errors";
|
||||||
import { ms } from "@app/lib/ms";
|
import { ms } from "@app/lib/ms";
|
||||||
import { validateHandlebarTemplate } from "@app/lib/template/validate-handlebars";
|
import { validateHandlebarTemplate } from "@app/lib/template/validate-handlebars";
|
||||||
@@ -72,7 +73,8 @@ export const identityProjectAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -85,7 +87,8 @@ export const identityProjectAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId: identityId,
|
actorId: identityId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
// we need to validate that the privilege given is not higher than the assigning users permission
|
// we need to validate that the privilege given is not higher than the assigning users permission
|
||||||
@@ -172,7 +175,8 @@ export const identityProjectAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -185,7 +189,8 @@ export const identityProjectAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId: identityProjectMembership.identityId,
|
actorId: identityProjectMembership.identityId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
// we need to validate that the privilege given is not higher than the assigning users permission
|
// we need to validate that the privilege given is not higher than the assigning users permission
|
||||||
@@ -288,7 +293,8 @@ export const identityProjectAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionIdentityActions.Edit,
|
ProjectPermissionIdentityActions.Edit,
|
||||||
@@ -300,7 +306,8 @@ export const identityProjectAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId: identityProjectMembership.identityId,
|
actorId: identityProjectMembership.identityId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
const permissionBoundary = validatePrivilegeChangeOperation(
|
const permissionBoundary = validatePrivilegeChangeOperation(
|
||||||
membership.shouldUseNewPrivilegeSystem,
|
membership.shouldUseNewPrivilegeSystem,
|
||||||
@@ -359,7 +366,8 @@ export const identityProjectAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionIdentityActions.Read,
|
ProjectPermissionIdentityActions.Read,
|
||||||
@@ -401,7 +409,8 @@ export const identityProjectAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: identityProjectMembership.projectId,
|
projectId: identityProjectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
import * as x509 from "@peculiar/x509";
|
import * as x509 from "@peculiar/x509";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { crypto } from "@app/lib/crypto/cryptography";
|
import { crypto } from "@app/lib/crypto/cryptography";
|
||||||
import { BadRequestError, InternalServerError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, InternalServerError, NotFoundError } from "@app/lib/errors";
|
||||||
import { isValidIp } from "@app/lib/ip";
|
import { isValidIp } from "@app/lib/ip";
|
||||||
@@ -78,7 +79,8 @@ export const kmipServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.KMS
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -131,7 +133,8 @@ export const kmipServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: kmipClient.projectId,
|
projectId: kmipClient.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.KMS
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -162,7 +165,8 @@ export const kmipServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: kmipClient.projectId,
|
projectId: kmipClient.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.KMS
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -195,7 +199,8 @@ export const kmipServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: kmipClient.projectId,
|
projectId: kmipClient.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.KMS
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionKmipActions.ReadClients, ProjectPermissionSub.Kmip);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionKmipActions.ReadClients, ProjectPermissionSub.Kmip);
|
||||||
@@ -216,7 +221,8 @@ export const kmipServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.KMS
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionKmipActions.ReadClients, ProjectPermissionSub.Kmip);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionKmipActions.ReadClients, ProjectPermissionSub.Kmip);
|
||||||
@@ -252,7 +258,8 @@ export const kmipServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: kmipClient.projectId,
|
projectId: kmipClient.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.KMS
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { MongoAbility, RawRuleOf } from "@casl/ability";
|
import { MongoAbility, RawRuleOf } from "@casl/ability";
|
||||||
import { MongoQuery } from "@ucast/mongo2js";
|
import { MongoQuery } from "@ucast/mongo2js";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { ActorAuthMethod, ActorType } from "@app/services/auth/auth-type";
|
import { ActorAuthMethod, ActorType } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
import { OrgPermissionSet } from "./org-permission";
|
import { OrgPermissionSet } from "./org-permission";
|
||||||
@@ -20,6 +21,7 @@ export type TGetUserProjectPermissionArg = {
|
|||||||
userId: string;
|
userId: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
authMethod: ActorAuthMethod;
|
authMethod: ActorAuthMethod;
|
||||||
|
actionProjectType: ActionProjectType;
|
||||||
userOrgId?: string;
|
userOrgId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,12 +29,14 @@ export type TGetIdentityProjectPermissionArg = {
|
|||||||
identityId: string;
|
identityId: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
identityOrgId?: string;
|
identityOrgId?: string;
|
||||||
|
actionProjectType: ActionProjectType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TGetServiceTokenProjectPermissionArg = {
|
export type TGetServiceTokenProjectPermissionArg = {
|
||||||
serviceTokenId: string;
|
serviceTokenId: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
actorOrgId?: string;
|
actorOrgId?: string;
|
||||||
|
actionProjectType: ActionProjectType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TGetProjectPermissionArg = {
|
export type TGetProjectPermissionArg = {
|
||||||
@@ -41,6 +45,7 @@ export type TGetProjectPermissionArg = {
|
|||||||
projectId: string;
|
projectId: string;
|
||||||
actorAuthMethod: ActorAuthMethod;
|
actorAuthMethod: ActorAuthMethod;
|
||||||
actorOrgId?: string;
|
actorOrgId?: string;
|
||||||
|
actionProjectType: ActionProjectType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TPermissionServiceFactory = {
|
export type TPermissionServiceFactory = {
|
||||||
@@ -138,7 +143,13 @@ export type TPermissionServiceFactory = {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
getUserProjectPermission: ({ userId, projectId, authMethod, userOrgId }: TGetUserProjectPermissionArg) => Promise<{
|
getUserProjectPermission: ({
|
||||||
|
userId,
|
||||||
|
projectId,
|
||||||
|
authMethod,
|
||||||
|
userOrgId,
|
||||||
|
actionProjectType
|
||||||
|
}: TGetUserProjectPermissionArg) => Promise<{
|
||||||
permission: MongoAbility<ProjectPermissionSet, MongoQuery>;
|
permission: MongoAbility<ProjectPermissionSet, MongoQuery>;
|
||||||
membership: {
|
membership: {
|
||||||
id: string;
|
id: string;
|
||||||
|
@@ -5,6 +5,7 @@ import { MongoQuery } from "@ucast/mongo2js";
|
|||||||
import handlebars from "handlebars";
|
import handlebars from "handlebars";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ActionProjectType,
|
||||||
OrgMembershipRole,
|
OrgMembershipRole,
|
||||||
ProjectMembershipRole,
|
ProjectMembershipRole,
|
||||||
ServiceTokenScopes,
|
ServiceTokenScopes,
|
||||||
@@ -213,7 +214,8 @@ export const permissionServiceFactory = ({
|
|||||||
userId,
|
userId,
|
||||||
projectId,
|
projectId,
|
||||||
authMethod,
|
authMethod,
|
||||||
userOrgId
|
userOrgId,
|
||||||
|
actionProjectType
|
||||||
}: TGetUserProjectPermissionArg): Promise<TProjectPermissionRT<ActorType.USER>> => {
|
}: TGetUserProjectPermissionArg): Promise<TProjectPermissionRT<ActorType.USER>> => {
|
||||||
const userProjectPermission = await permissionDAL.getProjectPermission(userId, projectId);
|
const userProjectPermission = await permissionDAL.getProjectPermission(userId, projectId);
|
||||||
if (!userProjectPermission) throw new ForbiddenRequestError({ name: "User not a part of the specified project" });
|
if (!userProjectPermission) throw new ForbiddenRequestError({ name: "User not a part of the specified project" });
|
||||||
@@ -240,6 +242,12 @@ export const permissionServiceFactory = ({
|
|||||||
userProjectPermission.orgRole
|
userProjectPermission.orgRole
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (actionProjectType !== ActionProjectType.Any && actionProjectType !== userProjectPermission.projectType) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `The project is of type ${userProjectPermission.projectType}. Operations of type ${actionProjectType} are not allowed.`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// join two permissions and pass to build the final permission set
|
// join two permissions and pass to build the final permission set
|
||||||
const rolePermissions = userProjectPermission.roles?.map(({ role, permissions }) => ({ role, permissions })) || [];
|
const rolePermissions = userProjectPermission.roles?.map(({ role, permissions }) => ({ role, permissions })) || [];
|
||||||
const additionalPrivileges =
|
const additionalPrivileges =
|
||||||
@@ -287,7 +295,8 @@ export const permissionServiceFactory = ({
|
|||||||
const getIdentityProjectPermission = async ({
|
const getIdentityProjectPermission = async ({
|
||||||
identityId,
|
identityId,
|
||||||
projectId,
|
projectId,
|
||||||
identityOrgId
|
identityOrgId,
|
||||||
|
actionProjectType
|
||||||
}: TGetIdentityProjectPermissionArg): Promise<TProjectPermissionRT<ActorType.IDENTITY>> => {
|
}: TGetIdentityProjectPermissionArg): Promise<TProjectPermissionRT<ActorType.IDENTITY>> => {
|
||||||
const identityProjectPermission = await permissionDAL.getProjectIdentityPermission(identityId, projectId);
|
const identityProjectPermission = await permissionDAL.getProjectIdentityPermission(identityId, projectId);
|
||||||
if (!identityProjectPermission)
|
if (!identityProjectPermission)
|
||||||
@@ -307,6 +316,12 @@ export const permissionServiceFactory = ({
|
|||||||
throw new ForbiddenRequestError({ name: "Identity is not a member of the specified organization" });
|
throw new ForbiddenRequestError({ name: "Identity is not a member of the specified organization" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (actionProjectType !== ActionProjectType.Any && actionProjectType !== identityProjectPermission.projectType) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `The project is of type ${identityProjectPermission.projectType}. Operations of type ${actionProjectType} are not allowed.`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const rolePermissions =
|
const rolePermissions =
|
||||||
identityProjectPermission.roles?.map(({ role, permissions }) => ({ role, permissions })) || [];
|
identityProjectPermission.roles?.map(({ role, permissions }) => ({ role, permissions })) || [];
|
||||||
const additionalPrivileges =
|
const additionalPrivileges =
|
||||||
@@ -361,7 +376,8 @@ export const permissionServiceFactory = ({
|
|||||||
const getServiceTokenProjectPermission = async ({
|
const getServiceTokenProjectPermission = async ({
|
||||||
serviceTokenId,
|
serviceTokenId,
|
||||||
projectId,
|
projectId,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType
|
||||||
}: TGetServiceTokenProjectPermissionArg) => {
|
}: TGetServiceTokenProjectPermissionArg) => {
|
||||||
const serviceToken = await serviceTokenDAL.findById(serviceTokenId);
|
const serviceToken = await serviceTokenDAL.findById(serviceTokenId);
|
||||||
if (!serviceToken) throw new NotFoundError({ message: `Service token with ID '${serviceTokenId}' not found` });
|
if (!serviceToken) throw new NotFoundError({ message: `Service token with ID '${serviceTokenId}' not found` });
|
||||||
@@ -386,6 +402,12 @@ export const permissionServiceFactory = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (actionProjectType !== ActionProjectType.Any && actionProjectType !== serviceTokenProject.type) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `The project is of type ${serviceTokenProject.type}. Operations of type ${actionProjectType} are not allowed.`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const scopes = ServiceTokenScopes.parse(serviceToken.scopes || []);
|
const scopes = ServiceTokenScopes.parse(serviceToken.scopes || []);
|
||||||
return {
|
return {
|
||||||
permission: buildServiceTokenProjectPermission(scopes, serviceToken.permissions),
|
permission: buildServiceTokenProjectPermission(scopes, serviceToken.permissions),
|
||||||
@@ -537,7 +559,8 @@ export const permissionServiceFactory = ({
|
|||||||
actorId: inputActorId,
|
actorId: inputActorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType
|
||||||
}: TGetProjectPermissionArg): Promise<TProjectPermissionRT<T>> => {
|
}: TGetProjectPermissionArg): Promise<TProjectPermissionRT<T>> => {
|
||||||
let actor = inputActor;
|
let actor = inputActor;
|
||||||
let actorId = inputActorId;
|
let actorId = inputActorId;
|
||||||
@@ -558,19 +581,22 @@ export const permissionServiceFactory = ({
|
|||||||
userId: actorId,
|
userId: actorId,
|
||||||
projectId,
|
projectId,
|
||||||
authMethod: actorAuthMethod,
|
authMethod: actorAuthMethod,
|
||||||
userOrgId: actorOrgId
|
userOrgId: actorOrgId,
|
||||||
|
actionProjectType
|
||||||
}) as Promise<TProjectPermissionRT<T>>;
|
}) as Promise<TProjectPermissionRT<T>>;
|
||||||
case ActorType.SERVICE:
|
case ActorType.SERVICE:
|
||||||
return getServiceTokenProjectPermission({
|
return getServiceTokenProjectPermission({
|
||||||
serviceTokenId: actorId,
|
serviceTokenId: actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType
|
||||||
}) as Promise<TProjectPermissionRT<T>>;
|
}) as Promise<TProjectPermissionRT<T>>;
|
||||||
case ActorType.IDENTITY:
|
case ActorType.IDENTITY:
|
||||||
return getIdentityProjectPermission({
|
return getIdentityProjectPermission({
|
||||||
identityId: actorId,
|
identityId: actorId,
|
||||||
projectId,
|
projectId,
|
||||||
identityOrgId: actorOrgId
|
identityOrgId: actorOrgId,
|
||||||
|
actionProjectType
|
||||||
}) as Promise<TProjectPermissionRT<T>>;
|
}) as Promise<TProjectPermissionRT<T>>;
|
||||||
default:
|
default:
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
|
@@ -1,29 +1,53 @@
|
|||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
|
import { Event, EventType } from "@app/ee/services/audit-log/audit-log-types";
|
||||||
import { ProjectPermissionCommitsActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionCommitsActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
import { NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
import { ActorAuthMethod, ActorType } from "@app/services/auth/auth-type";
|
import { ActorAuthMethod, ActorType } from "@app/services/auth/auth-type";
|
||||||
import { ResourceType, TFolderCommitServiceFactory } from "@app/services/folder-commit/folder-commit-service";
|
import { TFolderCommitDALFactory } from "@app/services/folder-commit/folder-commit-dal";
|
||||||
|
import {
|
||||||
|
ResourceType,
|
||||||
|
TCommitResourceChangeDTO,
|
||||||
|
TFolderCommitServiceFactory
|
||||||
|
} from "@app/services/folder-commit/folder-commit-service";
|
||||||
import {
|
import {
|
||||||
isFolderCommitChange,
|
isFolderCommitChange,
|
||||||
isSecretCommitChange
|
isSecretCommitChange
|
||||||
} from "@app/services/folder-commit-changes/folder-commit-changes-dal";
|
} from "@app/services/folder-commit-changes/folder-commit-changes-dal";
|
||||||
|
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
||||||
import { TProjectEnvDALFactory } from "@app/services/project-env/project-env-dal";
|
import { TProjectEnvDALFactory } from "@app/services/project-env/project-env-dal";
|
||||||
import { TSecretServiceFactory } from "@app/services/secret/secret-service";
|
import { TSecretServiceFactory } from "@app/services/secret/secret-service";
|
||||||
|
import { TProcessNewCommitRawDTO } from "@app/services/secret/secret-types";
|
||||||
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
|
import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";
|
||||||
import { TSecretFolderServiceFactory } from "@app/services/secret-folder/secret-folder-service";
|
import { TSecretFolderServiceFactory } from "@app/services/secret-folder/secret-folder-service";
|
||||||
|
import { TSecretV2BridgeServiceFactory } from "@app/services/secret-v2-bridge/secret-v2-bridge-service";
|
||||||
|
import { SecretOperations, SecretUpdateMode } from "@app/services/secret-v2-bridge/secret-v2-bridge-types";
|
||||||
|
|
||||||
import { TPermissionServiceFactory } from "../permission/permission-service-types";
|
import { TPermissionServiceFactory } from "../permission/permission-service-types";
|
||||||
|
import { TSecretApprovalPolicyServiceFactory } from "../secret-approval-policy/secret-approval-policy-service";
|
||||||
|
import { TSecretApprovalRequestServiceFactory } from "../secret-approval-request/secret-approval-request-service";
|
||||||
|
|
||||||
type TPitServiceFactoryDep = {
|
type TPitServiceFactoryDep = {
|
||||||
folderCommitService: TFolderCommitServiceFactory;
|
folderCommitService: TFolderCommitServiceFactory;
|
||||||
secretService: Pick<TSecretServiceFactory, "getSecretVersionsV2ByIds" | "getChangeVersions">;
|
secretService: Pick<TSecretServiceFactory, "getSecretVersionsV2ByIds" | "getChangeVersions">;
|
||||||
folderService: Pick<TSecretFolderServiceFactory, "getFolderById" | "getFolderVersions">;
|
folderService: Pick<
|
||||||
|
TSecretFolderServiceFactory,
|
||||||
|
"getFolderById" | "getFolderVersions" | "createManyFolders" | "updateManyFolders" | "deleteManyFolders"
|
||||||
|
>;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||||
folderDAL: Pick<TSecretFolderDALFactory, "findSecretPathByFolderIds">;
|
folderDAL: Pick<TSecretFolderDALFactory, "findSecretPathByFolderIds" | "findBySecretPath">;
|
||||||
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne">;
|
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne">;
|
||||||
|
secretApprovalRequestService: Pick<
|
||||||
|
TSecretApprovalRequestServiceFactory,
|
||||||
|
"generateSecretApprovalRequest" | "generateSecretApprovalRequestV2Bridge"
|
||||||
|
>;
|
||||||
|
secretApprovalPolicyService: Pick<TSecretApprovalPolicyServiceFactory, "getSecretApprovalPolicy">;
|
||||||
|
projectDAL: Pick<TProjectDALFactory, "checkProjectUpgradeStatus" | "findProjectBySlug" | "findById">;
|
||||||
|
secretV2BridgeService: TSecretV2BridgeServiceFactory;
|
||||||
|
folderCommitDAL: Pick<TFolderCommitDALFactory, "transaction">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TPitServiceFactory = ReturnType<typeof pitServiceFactory>;
|
export type TPitServiceFactory = ReturnType<typeof pitServiceFactory>;
|
||||||
@@ -34,7 +58,12 @@ export const pitServiceFactory = ({
|
|||||||
folderService,
|
folderService,
|
||||||
permissionService,
|
permissionService,
|
||||||
folderDAL,
|
folderDAL,
|
||||||
projectEnvDAL
|
projectEnvDAL,
|
||||||
|
secretApprovalRequestService,
|
||||||
|
secretApprovalPolicyService,
|
||||||
|
projectDAL,
|
||||||
|
secretV2BridgeService,
|
||||||
|
folderCommitDAL
|
||||||
}: TPitServiceFactoryDep) => {
|
}: TPitServiceFactoryDep) => {
|
||||||
const getCommitsCount = async ({
|
const getCommitsCount = async ({
|
||||||
actor,
|
actor,
|
||||||
@@ -320,7 +349,8 @@ export const pitServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(userPermission).throwUnlessCan(
|
ForbiddenError.from(userPermission).throwUnlessCan(
|
||||||
@@ -471,6 +501,347 @@ export const pitServiceFactory = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const processNewCommitRaw = async ({
|
||||||
|
actorId,
|
||||||
|
projectId,
|
||||||
|
environment,
|
||||||
|
actor,
|
||||||
|
actorOrgId,
|
||||||
|
actorAuthMethod,
|
||||||
|
secretPath,
|
||||||
|
message,
|
||||||
|
changes = {
|
||||||
|
secrets: {
|
||||||
|
create: [],
|
||||||
|
update: [],
|
||||||
|
delete: []
|
||||||
|
},
|
||||||
|
folders: {
|
||||||
|
create: [],
|
||||||
|
update: [],
|
||||||
|
delete: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}: {
|
||||||
|
actorId: string;
|
||||||
|
projectId: string;
|
||||||
|
environment: string;
|
||||||
|
actor: ActorType;
|
||||||
|
actorOrgId: string;
|
||||||
|
actorAuthMethod: ActorAuthMethod;
|
||||||
|
secretPath: string;
|
||||||
|
message: string;
|
||||||
|
changes: TProcessNewCommitRawDTO;
|
||||||
|
}) => {
|
||||||
|
const policy =
|
||||||
|
actor === ActorType.USER
|
||||||
|
? await secretApprovalPolicyService.getSecretApprovalPolicy(projectId, environment, secretPath)
|
||||||
|
: undefined;
|
||||||
|
const secretMutationEvents: Event[] = [];
|
||||||
|
|
||||||
|
const project = await projectDAL.findById(projectId);
|
||||||
|
if (project.enforceCapitalization) {
|
||||||
|
const caseViolatingSecretKeys = [
|
||||||
|
// Check create operations
|
||||||
|
...(changes.secrets?.create
|
||||||
|
?.filter((sec) => sec.secretKey !== sec.secretKey.toUpperCase())
|
||||||
|
.map((sec) => sec.secretKey) ?? []),
|
||||||
|
|
||||||
|
// Check update operations
|
||||||
|
...(changes.secrets?.update
|
||||||
|
?.filter((sec) => sec.newSecretName && sec.newSecretName !== sec.newSecretName.toUpperCase())
|
||||||
|
.map((sec) => sec.secretKey) ?? [])
|
||||||
|
];
|
||||||
|
|
||||||
|
if (caseViolatingSecretKeys.length) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `Secret names must be in UPPERCASE per project requirements: ${caseViolatingSecretKeys.join(
|
||||||
|
", "
|
||||||
|
)}. You can disable this requirement in project settings`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await folderCommitDAL.transaction(async (trx) => {
|
||||||
|
const targetFolder = await folderDAL.findBySecretPath(projectId, environment, secretPath, trx);
|
||||||
|
if (!targetFolder)
|
||||||
|
throw new NotFoundError({
|
||||||
|
message: `Folder with path '${secretPath}' in environment with slug '${environment}' not found`,
|
||||||
|
name: "CreateManySecret"
|
||||||
|
});
|
||||||
|
const commitChanges: TCommitResourceChangeDTO[] = [];
|
||||||
|
const folderChanges: { create: string[]; update: string[]; delete: string[] } = {
|
||||||
|
create: [],
|
||||||
|
update: [],
|
||||||
|
delete: []
|
||||||
|
};
|
||||||
|
|
||||||
|
if ((changes.folders?.create?.length ?? 0) > 0) {
|
||||||
|
const createdFolders = await folderService.createManyFolders({
|
||||||
|
projectId,
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
actorOrgId,
|
||||||
|
actorAuthMethod,
|
||||||
|
folders:
|
||||||
|
changes.folders?.create?.map((folder) => ({
|
||||||
|
name: folder.folderName,
|
||||||
|
environment,
|
||||||
|
path: secretPath,
|
||||||
|
description: folder.description
|
||||||
|
})) ?? [],
|
||||||
|
tx: trx,
|
||||||
|
commitChanges
|
||||||
|
});
|
||||||
|
const newFolderEvents = createdFolders.folders.map(
|
||||||
|
(folder) =>
|
||||||
|
({
|
||||||
|
type: EventType.CREATE_FOLDER,
|
||||||
|
metadata: {
|
||||||
|
environment,
|
||||||
|
folderId: folder.id,
|
||||||
|
folderName: folder.name,
|
||||||
|
folderPath: secretPath,
|
||||||
|
...(folder.description ? { description: folder.description } : {})
|
||||||
|
}
|
||||||
|
}) as Event
|
||||||
|
);
|
||||||
|
secretMutationEvents.push(...newFolderEvents);
|
||||||
|
folderChanges.create.push(...createdFolders.folders.map((folder) => folder.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((changes.folders?.update?.length ?? 0) > 0) {
|
||||||
|
const updatedFolders = await folderService.updateManyFolders({
|
||||||
|
projectId,
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
actorOrgId,
|
||||||
|
actorAuthMethod,
|
||||||
|
folders:
|
||||||
|
changes.folders?.update?.map((folder) => ({
|
||||||
|
environment,
|
||||||
|
path: secretPath,
|
||||||
|
id: folder.id,
|
||||||
|
name: folder.folderName,
|
||||||
|
description: folder.description
|
||||||
|
})) ?? [],
|
||||||
|
tx: trx,
|
||||||
|
commitChanges
|
||||||
|
});
|
||||||
|
|
||||||
|
const updatedFolderEvents = updatedFolders.newFolders.map(
|
||||||
|
(folder) =>
|
||||||
|
({
|
||||||
|
type: EventType.UPDATE_FOLDER,
|
||||||
|
metadata: {
|
||||||
|
environment,
|
||||||
|
folderId: folder.id,
|
||||||
|
folderPath: secretPath,
|
||||||
|
newFolderName: folder.name,
|
||||||
|
newFolderDescription: folder.description
|
||||||
|
}
|
||||||
|
}) as Event
|
||||||
|
);
|
||||||
|
secretMutationEvents.push(...updatedFolderEvents);
|
||||||
|
folderChanges.update.push(...updatedFolders.newFolders.map((folder) => folder.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((changes.folders?.delete?.length ?? 0) > 0) {
|
||||||
|
const deletedFolders = await folderService.deleteManyFolders({
|
||||||
|
projectId,
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
actorOrgId,
|
||||||
|
actorAuthMethod,
|
||||||
|
folders:
|
||||||
|
changes.folders?.delete?.map((folder) => ({
|
||||||
|
environment,
|
||||||
|
path: secretPath,
|
||||||
|
idOrName: folder.id
|
||||||
|
})) ?? [],
|
||||||
|
tx: trx,
|
||||||
|
commitChanges
|
||||||
|
});
|
||||||
|
const deletedFolderEvents = deletedFolders.folders.map(
|
||||||
|
(folder) =>
|
||||||
|
({
|
||||||
|
type: EventType.DELETE_FOLDER,
|
||||||
|
metadata: {
|
||||||
|
environment,
|
||||||
|
folderId: folder.id,
|
||||||
|
folderPath: secretPath,
|
||||||
|
folderName: folder.name
|
||||||
|
}
|
||||||
|
}) as Event
|
||||||
|
);
|
||||||
|
secretMutationEvents.push(...deletedFolderEvents);
|
||||||
|
folderChanges.delete.push(...deletedFolders.folders.map((folder) => folder.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (policy) {
|
||||||
|
if (
|
||||||
|
(changes.secrets?.create?.length ?? 0) > 0 ||
|
||||||
|
(changes.secrets?.update?.length ?? 0) > 0 ||
|
||||||
|
(changes.secrets?.delete?.length ?? 0) > 0
|
||||||
|
) {
|
||||||
|
const approval = await secretApprovalRequestService.generateSecretApprovalRequestV2Bridge({
|
||||||
|
policy,
|
||||||
|
secretPath,
|
||||||
|
environment,
|
||||||
|
projectId,
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
actorOrgId,
|
||||||
|
actorAuthMethod,
|
||||||
|
data: {
|
||||||
|
[SecretOperations.Create]:
|
||||||
|
changes.secrets?.create?.map((el) => ({
|
||||||
|
tagIds: el.tagIds,
|
||||||
|
secretValue: el.secretValue,
|
||||||
|
secretComment: el.secretComment,
|
||||||
|
metadata: el.metadata,
|
||||||
|
skipMultilineEncoding: el.skipMultilineEncoding,
|
||||||
|
secretKey: el.secretKey,
|
||||||
|
secretMetadata: el.secretMetadata
|
||||||
|
})) ?? [],
|
||||||
|
[SecretOperations.Update]:
|
||||||
|
changes.secrets?.update?.map((el) => ({
|
||||||
|
tagIds: el.tagIds,
|
||||||
|
newSecretName: el.newSecretName,
|
||||||
|
secretValue: el.secretValue,
|
||||||
|
secretComment: el.secretComment,
|
||||||
|
metadata: el.metadata,
|
||||||
|
skipMultilineEncoding: el.skipMultilineEncoding,
|
||||||
|
secretKey: el.secretKey,
|
||||||
|
secretMetadata: el.secretMetadata
|
||||||
|
})) ?? [],
|
||||||
|
[SecretOperations.Delete]:
|
||||||
|
changes.secrets?.delete?.map((el) => ({
|
||||||
|
secretKey: el.secretKey
|
||||||
|
})) ?? []
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
approvalId: approval.id,
|
||||||
|
folderChanges,
|
||||||
|
secretMutationEvents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
folderChanges,
|
||||||
|
secretMutationEvents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((changes.secrets?.create?.length ?? 0) > 0) {
|
||||||
|
const newSecrets = await secretV2BridgeService.createManySecret({
|
||||||
|
secretPath,
|
||||||
|
environment,
|
||||||
|
projectId,
|
||||||
|
actorAuthMethod,
|
||||||
|
actorOrgId,
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
secrets: changes.secrets?.create ?? [],
|
||||||
|
tx: trx,
|
||||||
|
commitChanges
|
||||||
|
});
|
||||||
|
secretMutationEvents.push({
|
||||||
|
type: EventType.CREATE_SECRETS,
|
||||||
|
metadata: {
|
||||||
|
environment,
|
||||||
|
secretPath,
|
||||||
|
secrets: newSecrets.map((secret) => ({
|
||||||
|
secretId: secret.id,
|
||||||
|
secretKey: secret.secretKey,
|
||||||
|
secretVersion: secret.version
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if ((changes.secrets?.update?.length ?? 0) > 0) {
|
||||||
|
const updatedSecrets = await secretV2BridgeService.updateManySecret({
|
||||||
|
secretPath,
|
||||||
|
environment,
|
||||||
|
projectId,
|
||||||
|
actorAuthMethod,
|
||||||
|
actorOrgId,
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
secrets: changes.secrets?.update ?? [],
|
||||||
|
mode: SecretUpdateMode.FailOnNotFound,
|
||||||
|
tx: trx,
|
||||||
|
commitChanges
|
||||||
|
});
|
||||||
|
secretMutationEvents.push({
|
||||||
|
type: EventType.UPDATE_SECRETS,
|
||||||
|
metadata: {
|
||||||
|
environment,
|
||||||
|
secretPath,
|
||||||
|
secrets: updatedSecrets.map((secret) => ({
|
||||||
|
secretId: secret.id,
|
||||||
|
secretKey: secret.secretKey,
|
||||||
|
secretVersion: secret.version
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if ((changes.secrets?.delete?.length ?? 0) > 0) {
|
||||||
|
const deletedSecrets = await secretV2BridgeService.deleteManySecret({
|
||||||
|
secretPath,
|
||||||
|
environment,
|
||||||
|
projectId,
|
||||||
|
actorAuthMethod,
|
||||||
|
actorOrgId,
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
secrets: changes.secrets?.delete ?? [],
|
||||||
|
tx: trx,
|
||||||
|
commitChanges
|
||||||
|
});
|
||||||
|
secretMutationEvents.push({
|
||||||
|
type: EventType.DELETE_SECRETS,
|
||||||
|
metadata: {
|
||||||
|
environment,
|
||||||
|
secretPath,
|
||||||
|
secrets: deletedSecrets.map((secret) => ({
|
||||||
|
secretId: secret.id,
|
||||||
|
secretKey: secret.secretKey,
|
||||||
|
secretVersion: secret.version
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (commitChanges?.length > 0) {
|
||||||
|
const commit = await folderCommitService.createCommit(
|
||||||
|
{
|
||||||
|
actor: {
|
||||||
|
type: actor || ActorType.PLATFORM,
|
||||||
|
metadata: {
|
||||||
|
id: actorId
|
||||||
|
}
|
||||||
|
},
|
||||||
|
message,
|
||||||
|
folderId: targetFolder.id,
|
||||||
|
changes: commitChanges
|
||||||
|
},
|
||||||
|
trx
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
folderChanges,
|
||||||
|
commitId: commit?.id,
|
||||||
|
secretMutationEvents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
folderChanges,
|
||||||
|
secretMutationEvents
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getCommitsCount,
|
getCommitsCount,
|
||||||
getCommitsForFolder,
|
getCommitsForFolder,
|
||||||
@@ -478,6 +849,7 @@ export const pitServiceFactory = ({
|
|||||||
compareCommitChanges,
|
compareCommitChanges,
|
||||||
rollbackToCommit,
|
rollbackToCommit,
|
||||||
revertCommit,
|
revertCommit,
|
||||||
getFolderStateAtCommit
|
getFolderStateAtCommit,
|
||||||
|
processNewCommitRaw
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
import { ProjectType } from "@app/db/schemas";
|
||||||
import {
|
import {
|
||||||
InfisicalProjectTemplate,
|
InfisicalProjectTemplate,
|
||||||
TUnpackedPermission
|
TUnpackedPermission
|
||||||
@@ -6,18 +7,21 @@ import { getPredefinedRoles } from "@app/services/project-role/project-role-fns"
|
|||||||
|
|
||||||
import { ProjectTemplateDefaultEnvironments } from "./project-template-constants";
|
import { ProjectTemplateDefaultEnvironments } from "./project-template-constants";
|
||||||
|
|
||||||
export const getDefaultProjectTemplate = (orgId: string) => ({
|
export const getDefaultProjectTemplate = (orgId: string, type: ProjectType) => ({
|
||||||
id: "b11b49a9-09a9-4443-916a-4246f9ff2c69", // random ID to appease zod
|
id: "b11b49a9-09a9-4443-916a-4246f9ff2c69", // random ID to appease zod
|
||||||
|
type,
|
||||||
name: InfisicalProjectTemplate.Default,
|
name: InfisicalProjectTemplate.Default,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
description: `Infisical's default project template`,
|
description: `Infisical's ${type} default project template`,
|
||||||
environments: ProjectTemplateDefaultEnvironments,
|
environments: type === ProjectType.SecretManager ? ProjectTemplateDefaultEnvironments : null,
|
||||||
roles: getPredefinedRoles({ projectId: "project-template" }) as Array<{
|
roles: [...getPredefinedRoles({ projectId: "project-template", projectType: type })].map(
|
||||||
name: string;
|
({ name, slug, permissions }) => ({
|
||||||
slug: string;
|
name,
|
||||||
permissions: TUnpackedPermission[];
|
slug,
|
||||||
}>,
|
permissions: permissions as TUnpackedPermission[]
|
||||||
|
})
|
||||||
|
),
|
||||||
orgId
|
orgId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
import { packRules } from "@casl/ability/extra";
|
import { packRules } from "@casl/ability/extra";
|
||||||
|
|
||||||
import { TProjectTemplates } from "@app/db/schemas";
|
import { ProjectType, TProjectTemplates } from "@app/db/schemas";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
@@ -29,11 +29,13 @@ const $unpackProjectTemplate = ({ roles, environments, ...rest }: TProjectTempla
|
|||||||
...rest,
|
...rest,
|
||||||
environments: environments as TProjectTemplateEnvironment[],
|
environments: environments as TProjectTemplateEnvironment[],
|
||||||
roles: [
|
roles: [
|
||||||
...getPredefinedRoles({ projectId: "project-template" }).map(({ name, slug, permissions }) => ({
|
...getPredefinedRoles({ projectId: "project-template", projectType: rest.type as ProjectType }).map(
|
||||||
name,
|
({ name, slug, permissions }) => ({
|
||||||
slug,
|
name,
|
||||||
permissions: permissions as TUnpackedPermission[]
|
slug,
|
||||||
})),
|
permissions: permissions as TUnpackedPermission[]
|
||||||
|
})
|
||||||
|
),
|
||||||
...(roles as TProjectTemplateRole[]).map((role) => ({
|
...(roles as TProjectTemplateRole[]).map((role) => ({
|
||||||
...role,
|
...role,
|
||||||
permissions: unpackPermissions(role.permissions)
|
permissions: unpackPermissions(role.permissions)
|
||||||
@@ -46,7 +48,10 @@ export const projectTemplateServiceFactory = ({
|
|||||||
permissionService,
|
permissionService,
|
||||||
projectTemplateDAL
|
projectTemplateDAL
|
||||||
}: TProjectTemplatesServiceFactoryDep): TProjectTemplateServiceFactory => {
|
}: TProjectTemplatesServiceFactoryDep): TProjectTemplateServiceFactory => {
|
||||||
const listProjectTemplatesByOrg: TProjectTemplateServiceFactory["listProjectTemplatesByOrg"] = async (actor) => {
|
const listProjectTemplatesByOrg: TProjectTemplateServiceFactory["listProjectTemplatesByOrg"] = async (
|
||||||
|
actor,
|
||||||
|
type
|
||||||
|
) => {
|
||||||
const plan = await licenseService.getPlan(actor.orgId);
|
const plan = await licenseService.getPlan(actor.orgId);
|
||||||
|
|
||||||
if (!plan.projectTemplates)
|
if (!plan.projectTemplates)
|
||||||
@@ -65,11 +70,14 @@ export const projectTemplateServiceFactory = ({
|
|||||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.ProjectTemplates);
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.ProjectTemplates);
|
||||||
|
|
||||||
const projectTemplates = await projectTemplateDAL.find({
|
const projectTemplates = await projectTemplateDAL.find({
|
||||||
orgId: actor.orgId
|
orgId: actor.orgId,
|
||||||
|
...(type ? { type } : {})
|
||||||
});
|
});
|
||||||
|
|
||||||
return [
|
return [
|
||||||
getDefaultProjectTemplate(actor.orgId),
|
...(type
|
||||||
|
? [getDefaultProjectTemplate(actor.orgId, type)]
|
||||||
|
: Object.values(ProjectType).map((projectType) => getDefaultProjectTemplate(actor.orgId, projectType))),
|
||||||
...projectTemplates.map((template) => $unpackProjectTemplate(template))
|
...projectTemplates.map((template) => $unpackProjectTemplate(template))
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
@@ -134,7 +142,7 @@ export const projectTemplateServiceFactory = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const createProjectTemplate: TProjectTemplateServiceFactory["createProjectTemplate"] = async (
|
const createProjectTemplate: TProjectTemplateServiceFactory["createProjectTemplate"] = async (
|
||||||
{ roles, environments, ...params },
|
{ roles, environments, type, ...params },
|
||||||
actor
|
actor
|
||||||
) => {
|
) => {
|
||||||
const plan = await licenseService.getPlan(actor.orgId);
|
const plan = await licenseService.getPlan(actor.orgId);
|
||||||
@@ -154,6 +162,10 @@ export const projectTemplateServiceFactory = ({
|
|||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.ProjectTemplates);
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.ProjectTemplates);
|
||||||
|
|
||||||
|
if (environments && type !== ProjectType.SecretManager) {
|
||||||
|
throw new BadRequestError({ message: "Cannot configure environments for non-SecretManager project templates" });
|
||||||
|
}
|
||||||
|
|
||||||
if (environments && plan.environmentLimit !== null && environments.length > plan.environmentLimit) {
|
if (environments && plan.environmentLimit !== null && environments.length > plan.environmentLimit) {
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||||
@@ -176,8 +188,10 @@ export const projectTemplateServiceFactory = ({
|
|||||||
const projectTemplate = await projectTemplateDAL.create({
|
const projectTemplate = await projectTemplateDAL.create({
|
||||||
...params,
|
...params,
|
||||||
roles: JSON.stringify(roles.map((role) => ({ ...role, permissions: packRules(role.permissions) }))),
|
roles: JSON.stringify(roles.map((role) => ({ ...role, permissions: packRules(role.permissions) }))),
|
||||||
environments: environments ? JSON.stringify(environments ?? ProjectTemplateDefaultEnvironments) : null,
|
environments:
|
||||||
orgId: actor.orgId
|
type === ProjectType.SecretManager ? JSON.stringify(environments ?? ProjectTemplateDefaultEnvironments) : null,
|
||||||
|
orgId: actor.orgId,
|
||||||
|
type
|
||||||
});
|
});
|
||||||
|
|
||||||
return $unpackProjectTemplate(projectTemplate);
|
return $unpackProjectTemplate(projectTemplate);
|
||||||
@@ -208,6 +222,11 @@ export const projectTemplateServiceFactory = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.ProjectTemplates);
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.ProjectTemplates);
|
||||||
|
if (projectTemplate.type !== ProjectType.SecretManager && environments)
|
||||||
|
throw new BadRequestError({ message: "Cannot configure environments for non-SecretManager project templates" });
|
||||||
|
|
||||||
|
if (projectTemplate.type === ProjectType.SecretManager && environments === null)
|
||||||
|
throw new BadRequestError({ message: "Environments cannot be removed for SecretManager project templates" });
|
||||||
|
|
||||||
if (environments && plan.environmentLimit !== null && environments.length > plan.environmentLimit) {
|
if (environments && plan.environmentLimit !== null && environments.length > plan.environmentLimit) {
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { ProjectMembershipRole, TProjectEnvironments } from "@app/db/schemas";
|
import { ProjectMembershipRole, ProjectType, TProjectEnvironments } from "@app/db/schemas";
|
||||||
import { TProjectPermissionV2Schema } from "@app/ee/services/permission/project-permission";
|
import { TProjectPermissionV2Schema } from "@app/ee/services/permission/project-permission";
|
||||||
import { OrgServiceActor } from "@app/lib/types";
|
import { OrgServiceActor } from "@app/lib/types";
|
||||||
import { UnpackedPermissionSchema } from "@app/server/routes/sanitizedSchema/permission";
|
import { UnpackedPermissionSchema } from "@app/server/routes/sanitizedSchema/permission";
|
||||||
@@ -15,6 +15,7 @@ export type TProjectTemplateRole = {
|
|||||||
|
|
||||||
export type TCreateProjectTemplateDTO = {
|
export type TCreateProjectTemplateDTO = {
|
||||||
name: string;
|
name: string;
|
||||||
|
type: ProjectType;
|
||||||
description?: string;
|
description?: string;
|
||||||
roles: TProjectTemplateRole[];
|
roles: TProjectTemplateRole[];
|
||||||
environments?: TProjectTemplateEnvironment[] | null;
|
environments?: TProjectTemplateEnvironment[] | null;
|
||||||
@@ -29,11 +30,15 @@ export enum InfisicalProjectTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type TProjectTemplateServiceFactory = {
|
export type TProjectTemplateServiceFactory = {
|
||||||
listProjectTemplatesByOrg: (actor: OrgServiceActor) => Promise<
|
listProjectTemplatesByOrg: (
|
||||||
|
actor: OrgServiceActor,
|
||||||
|
type?: ProjectType
|
||||||
|
) => Promise<
|
||||||
(
|
(
|
||||||
| {
|
| {
|
||||||
id: string;
|
id: string;
|
||||||
name: InfisicalProjectTemplate;
|
name: InfisicalProjectTemplate;
|
||||||
|
type: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
description: string;
|
description: string;
|
||||||
@@ -58,6 +63,7 @@ export type TProjectTemplateServiceFactory = {
|
|||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
environments: TProjectTemplateEnvironment[];
|
environments: TProjectTemplateEnvironment[];
|
||||||
|
type: string;
|
||||||
roles: {
|
roles: {
|
||||||
permissions: {
|
permissions: {
|
||||||
action: string[];
|
action: string[];
|
||||||
@@ -94,6 +100,7 @@ export type TProjectTemplateServiceFactory = {
|
|||||||
}[];
|
}[];
|
||||||
name: string;
|
name: string;
|
||||||
orgId: string;
|
orgId: string;
|
||||||
|
type: string;
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
@@ -118,6 +125,7 @@ export type TProjectTemplateServiceFactory = {
|
|||||||
name: string;
|
name: string;
|
||||||
orgId: string;
|
orgId: string;
|
||||||
id: string;
|
id: string;
|
||||||
|
type: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
description?: string | null | undefined;
|
description?: string | null | undefined;
|
||||||
@@ -140,6 +148,7 @@ export type TProjectTemplateServiceFactory = {
|
|||||||
name: string;
|
name: string;
|
||||||
orgId: string;
|
orgId: string;
|
||||||
id: string;
|
id: string;
|
||||||
|
type: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
description?: string | null | undefined;
|
description?: string | null | undefined;
|
||||||
@@ -162,6 +171,7 @@ export type TProjectTemplateServiceFactory = {
|
|||||||
}[];
|
}[];
|
||||||
name: string;
|
name: string;
|
||||||
orgId: string;
|
orgId: string;
|
||||||
|
type: string;
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
@@ -184,6 +194,7 @@ export type TProjectTemplateServiceFactory = {
|
|||||||
name: string;
|
name: string;
|
||||||
}[];
|
}[];
|
||||||
name: string;
|
name: string;
|
||||||
|
type: string;
|
||||||
orgId: string;
|
orgId: string;
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { ForbiddenError, MongoAbility, RawRuleOf } from "@casl/ability";
|
import { ForbiddenError, MongoAbility, RawRuleOf } from "@casl/ability";
|
||||||
import { PackRule, packRules, unpackRules } from "@casl/ability/extra";
|
import { PackRule, packRules, unpackRules } from "@casl/ability/extra";
|
||||||
|
|
||||||
import { TableName } from "@app/db/schemas";
|
import { ActionProjectType, TableName } from "@app/db/schemas";
|
||||||
import { BadRequestError, NotFoundError, PermissionBoundaryError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError, PermissionBoundaryError } from "@app/lib/errors";
|
||||||
import { ms } from "@app/lib/ms";
|
import { ms } from "@app/lib/ms";
|
||||||
import { validateHandlebarTemplate } from "@app/lib/template/validate-handlebars";
|
import { validateHandlebarTemplate } from "@app/lib/template/validate-handlebars";
|
||||||
@@ -61,7 +61,8 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: projectMembership.projectId,
|
projectId: projectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionMemberActions.Edit, ProjectPermissionSub.Member);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionMemberActions.Edit, ProjectPermissionSub.Member);
|
||||||
const { permission: targetUserPermission, membership } = await permissionService.getProjectPermission({
|
const { permission: targetUserPermission, membership } = await permissionService.getProjectPermission({
|
||||||
@@ -69,7 +70,8 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId: projectMembership.userId,
|
actorId: projectMembership.userId,
|
||||||
projectId: projectMembership.projectId,
|
projectId: projectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
// we need to validate that the privilege given is not higher than the assigning users permission
|
// we need to validate that the privilege given is not higher than the assigning users permission
|
||||||
@@ -164,7 +166,8 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: projectMembership.projectId,
|
projectId: projectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionMemberActions.Edit, ProjectPermissionSub.Member);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionMemberActions.Edit, ProjectPermissionSub.Member);
|
||||||
const { permission: targetUserPermission } = await permissionService.getProjectPermission({
|
const { permission: targetUserPermission } = await permissionService.getProjectPermission({
|
||||||
@@ -172,7 +175,8 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId: projectMembership.userId,
|
actorId: projectMembership.userId,
|
||||||
projectId: projectMembership.projectId,
|
projectId: projectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
|
|
||||||
// we need to validate that the privilege given is not higher than the assigning users permission
|
// we need to validate that the privilege given is not higher than the assigning users permission
|
||||||
@@ -272,7 +276,8 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: projectMembership.projectId,
|
projectId: projectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionMemberActions.Edit, ProjectPermissionSub.Member);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionMemberActions.Edit, ProjectPermissionSub.Member);
|
||||||
|
|
||||||
@@ -317,7 +322,8 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: projectMembership.projectId,
|
projectId: projectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionMemberActions.Read, ProjectPermissionSub.Member);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionMemberActions.Read, ProjectPermissionSub.Member);
|
||||||
|
|
||||||
@@ -343,7 +349,8 @@ export const projectUserAdditionalPrivilegeServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: projectMembership.projectId,
|
projectId: projectMembership.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionMemberActions.Read, ProjectPermissionSub.Member);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionMemberActions.Read, ProjectPermissionSub.Member);
|
||||||
|
|
||||||
|
@@ -410,7 +410,7 @@ export const samlConfigServiceFactory = ({
|
|||||||
}
|
}
|
||||||
await licenseService.updateSubscriptionOrgMemberCount(organization.id);
|
await licenseService.updateSubscriptionOrgMemberCount(organization.id);
|
||||||
|
|
||||||
const isUserCompleted = Boolean(user.isAccepted);
|
const isUserCompleted = Boolean(user.isAccepted && user.isEmailVerified);
|
||||||
const userEnc = await userDAL.findUserEncKeyByUserId(user.id);
|
const userEnc = await userDAL.findUserEncKeyByUserId(user.id);
|
||||||
const providerAuthToken = crypto.jwt().sign(
|
const providerAuthToken = crypto.jwt().sign(
|
||||||
{
|
{
|
||||||
|
@@ -579,6 +579,9 @@ export const scimServiceFactory = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const serverCfg = await getServerCfg();
|
const serverCfg = await getServerCfg();
|
||||||
|
const hasEmailChanged = email?.toLowerCase() !== membership.email;
|
||||||
|
const defaultEmailVerified =
|
||||||
|
org.orgAuthMethod === OrgAuthMethod.OIDC ? serverCfg.trustOidcEmails : serverCfg.trustSamlEmails;
|
||||||
await userDAL.transaction(async (tx) => {
|
await userDAL.transaction(async (tx) => {
|
||||||
await userAliasDAL.update(
|
await userAliasDAL.update(
|
||||||
{
|
{
|
||||||
@@ -605,8 +608,7 @@ export const scimServiceFactory = ({
|
|||||||
firstName,
|
firstName,
|
||||||
email: email?.toLowerCase(),
|
email: email?.toLowerCase(),
|
||||||
lastName,
|
lastName,
|
||||||
isEmailVerified:
|
isEmailVerified: hasEmailChanged ? defaultEmailVerified : undefined
|
||||||
org.orgAuthMethod === OrgAuthMethod.OIDC ? serverCfg.trustOidcEmails : serverCfg.trustSamlEmails
|
|
||||||
},
|
},
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
@@ -23,6 +23,7 @@ export const secretApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
filter: TFindFilter<TSecretApprovalPolicies & { projectId: string }>,
|
filter: TFindFilter<TSecretApprovalPolicies & { projectId: string }>,
|
||||||
customFilter?: {
|
customFilter?: {
|
||||||
sapId?: string;
|
sapId?: string;
|
||||||
|
envId?: string;
|
||||||
}
|
}
|
||||||
) =>
|
) =>
|
||||||
tx(TableName.SecretApprovalPolicy)
|
tx(TableName.SecretApprovalPolicy)
|
||||||
@@ -33,7 +34,17 @@ export const secretApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
void qb.where(`${TableName.SecretApprovalPolicy}.id`, "=", customFilter.sapId);
|
void qb.where(`${TableName.SecretApprovalPolicy}.id`, "=", customFilter.sapId);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.join(TableName.Environment, `${TableName.SecretApprovalPolicy}.envId`, `${TableName.Environment}.id`)
|
.join(
|
||||||
|
TableName.SecretApprovalPolicyEnvironment,
|
||||||
|
`${TableName.SecretApprovalPolicyEnvironment}.policyId`,
|
||||||
|
`${TableName.SecretApprovalPolicy}.id`
|
||||||
|
)
|
||||||
|
.join(TableName.Environment, `${TableName.SecretApprovalPolicyEnvironment}.envId`, `${TableName.Environment}.id`)
|
||||||
|
.where((qb) => {
|
||||||
|
if (customFilter?.envId) {
|
||||||
|
void qb.where(`${TableName.SecretApprovalPolicyEnvironment}.envId`, "=", customFilter.envId);
|
||||||
|
}
|
||||||
|
})
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
TableName.SecretApprovalPolicyApprover,
|
TableName.SecretApprovalPolicyApprover,
|
||||||
`${TableName.SecretApprovalPolicy}.id`,
|
`${TableName.SecretApprovalPolicy}.id`,
|
||||||
@@ -97,7 +108,7 @@ export const secretApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
.select(
|
.select(
|
||||||
tx.ref("name").withSchema(TableName.Environment).as("envName"),
|
tx.ref("name").withSchema(TableName.Environment).as("envName"),
|
||||||
tx.ref("slug").withSchema(TableName.Environment).as("envSlug"),
|
tx.ref("slug").withSchema(TableName.Environment).as("envSlug"),
|
||||||
tx.ref("id").withSchema(TableName.Environment).as("envId"),
|
tx.ref("id").withSchema(TableName.Environment).as("environmentId"),
|
||||||
tx.ref("projectId").withSchema(TableName.Environment)
|
tx.ref("projectId").withSchema(TableName.Environment)
|
||||||
)
|
)
|
||||||
.select(selectAllTableCols(TableName.SecretApprovalPolicy))
|
.select(selectAllTableCols(TableName.SecretApprovalPolicy))
|
||||||
@@ -146,6 +157,15 @@ export const secretApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
firstName,
|
firstName,
|
||||||
lastName
|
lastName
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "environmentId",
|
||||||
|
label: "environments" as const,
|
||||||
|
mapper: ({ environmentId, envName, envSlug }) => ({
|
||||||
|
id: environmentId,
|
||||||
|
name: envName,
|
||||||
|
slug: envSlug
|
||||||
|
})
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -160,6 +180,7 @@ export const secretApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
filter: TFindFilter<TSecretApprovalPolicies & { projectId: string }>,
|
filter: TFindFilter<TSecretApprovalPolicies & { projectId: string }>,
|
||||||
customFilter?: {
|
customFilter?: {
|
||||||
sapId?: string;
|
sapId?: string;
|
||||||
|
envId?: string;
|
||||||
},
|
},
|
||||||
tx?: Knex
|
tx?: Knex
|
||||||
) => {
|
) => {
|
||||||
@@ -221,6 +242,15 @@ export const secretApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
mapper: ({ approverGroupUserId: userId }) => ({
|
mapper: ({ approverGroupUserId: userId }) => ({
|
||||||
userId
|
userId
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "environmentId",
|
||||||
|
label: "environments" as const,
|
||||||
|
mapper: ({ environmentId, envName, envSlug }) => ({
|
||||||
|
id: environmentId,
|
||||||
|
name: envName,
|
||||||
|
slug: envSlug
|
||||||
|
})
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -235,5 +265,74 @@ export const secretApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
return softDeletedPolicy;
|
return softDeletedPolicy;
|
||||||
};
|
};
|
||||||
|
|
||||||
return { ...secretApprovalPolicyOrm, findById, find, softDeleteById };
|
const findPolicyByEnvIdAndSecretPath = async (
|
||||||
|
{ envIds, secretPath }: { envIds: string[]; secretPath: string },
|
||||||
|
tx?: Knex
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const docs = await (tx || db.replicaNode())(TableName.SecretApprovalPolicy)
|
||||||
|
.join(
|
||||||
|
TableName.SecretApprovalPolicyEnvironment,
|
||||||
|
`${TableName.SecretApprovalPolicyEnvironment}.policyId`,
|
||||||
|
`${TableName.SecretApprovalPolicy}.id`
|
||||||
|
)
|
||||||
|
.join(
|
||||||
|
TableName.Environment,
|
||||||
|
`${TableName.SecretApprovalPolicyEnvironment}.envId`,
|
||||||
|
`${TableName.Environment}.id`
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
|
buildFindFilter(
|
||||||
|
{
|
||||||
|
$in: {
|
||||||
|
envId: envIds
|
||||||
|
}
|
||||||
|
},
|
||||||
|
TableName.SecretApprovalPolicyEnvironment
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
|
buildFindFilter(
|
||||||
|
{
|
||||||
|
secretPath
|
||||||
|
},
|
||||||
|
TableName.SecretApprovalPolicy
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.whereNull(`${TableName.SecretApprovalPolicy}.deletedAt`)
|
||||||
|
.orderBy("deletedAt", "desc")
|
||||||
|
.orderByRaw(`"deletedAt" IS NULL`)
|
||||||
|
.select(selectAllTableCols(TableName.SecretApprovalPolicy))
|
||||||
|
.select(db.ref("name").withSchema(TableName.Environment).as("envName"))
|
||||||
|
.select(db.ref("slug").withSchema(TableName.Environment).as("envSlug"))
|
||||||
|
.select(db.ref("id").withSchema(TableName.Environment).as("environmentId"))
|
||||||
|
.select(db.ref("projectId").withSchema(TableName.Environment));
|
||||||
|
const formattedDocs = sqlNestRelationships({
|
||||||
|
data: docs,
|
||||||
|
key: "id",
|
||||||
|
parentMapper: (data) => ({
|
||||||
|
projectId: data.projectId,
|
||||||
|
...SecretApprovalPoliciesSchema.parse(data)
|
||||||
|
}),
|
||||||
|
childrenMapper: [
|
||||||
|
{
|
||||||
|
key: "environmentId",
|
||||||
|
label: "environments" as const,
|
||||||
|
mapper: ({ environmentId: id, envName, envSlug }) => ({
|
||||||
|
id,
|
||||||
|
name: envName,
|
||||||
|
slug: envSlug
|
||||||
|
})
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
return formattedDocs?.[0];
|
||||||
|
} catch (error) {
|
||||||
|
throw new DatabaseError({ error, name: "findPolicyByEnvIdAndSecretPath" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return { ...secretApprovalPolicyOrm, findById, find, softDeleteById, findPolicyByEnvIdAndSecretPath };
|
||||||
};
|
};
|
||||||
|
@@ -0,0 +1,32 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { TDbClient } from "@app/db";
|
||||||
|
import { TableName } from "@app/db/schemas";
|
||||||
|
import { DatabaseError } from "@app/lib/errors";
|
||||||
|
import { buildFindFilter, ormify, selectAllTableCols } from "@app/lib/knex";
|
||||||
|
|
||||||
|
export type TSecretApprovalPolicyEnvironmentDALFactory = ReturnType<typeof secretApprovalPolicyEnvironmentDALFactory>;
|
||||||
|
|
||||||
|
export const secretApprovalPolicyEnvironmentDALFactory = (db: TDbClient) => {
|
||||||
|
const secretApprovalPolicyEnvironmentOrm = ormify(db, TableName.SecretApprovalPolicyEnvironment);
|
||||||
|
|
||||||
|
const findAvailablePoliciesByEnvId = async (envId: string, tx?: Knex) => {
|
||||||
|
try {
|
||||||
|
const docs = await (tx || db.replicaNode())(TableName.SecretApprovalPolicyEnvironment)
|
||||||
|
.join(
|
||||||
|
TableName.SecretApprovalPolicy,
|
||||||
|
`${TableName.SecretApprovalPolicyEnvironment}.policyId`,
|
||||||
|
`${TableName.SecretApprovalPolicy}.id`
|
||||||
|
)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
|
.where(buildFindFilter({ envId }, TableName.SecretApprovalPolicyEnvironment))
|
||||||
|
.whereNull(`${TableName.SecretApprovalPolicy}.deletedAt`)
|
||||||
|
.select(selectAllTableCols(TableName.SecretApprovalPolicyEnvironment));
|
||||||
|
return docs;
|
||||||
|
} catch (error) {
|
||||||
|
throw new DatabaseError({ error, name: "findAvailablePoliciesByEnvId" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return { ...secretApprovalPolicyEnvironmentOrm, findAvailablePoliciesByEnvId };
|
||||||
|
};
|
@@ -1,6 +1,7 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
import picomatch from "picomatch";
|
import picomatch from "picomatch";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
@@ -18,6 +19,7 @@ import {
|
|||||||
TSecretApprovalPolicyBypasserDALFactory
|
TSecretApprovalPolicyBypasserDALFactory
|
||||||
} from "./secret-approval-policy-approver-dal";
|
} from "./secret-approval-policy-approver-dal";
|
||||||
import { TSecretApprovalPolicyDALFactory } from "./secret-approval-policy-dal";
|
import { TSecretApprovalPolicyDALFactory } from "./secret-approval-policy-dal";
|
||||||
|
import { TSecretApprovalPolicyEnvironmentDALFactory } from "./secret-approval-policy-environment-dal";
|
||||||
import {
|
import {
|
||||||
TCreateSapDTO,
|
TCreateSapDTO,
|
||||||
TDeleteSapDTO,
|
TDeleteSapDTO,
|
||||||
@@ -35,12 +37,13 @@ const getPolicyScore = (policy: { secretPath?: string | null }) =>
|
|||||||
type TSecretApprovalPolicyServiceFactoryDep = {
|
type TSecretApprovalPolicyServiceFactoryDep = {
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||||
secretApprovalPolicyDAL: TSecretApprovalPolicyDALFactory;
|
secretApprovalPolicyDAL: TSecretApprovalPolicyDALFactory;
|
||||||
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne">;
|
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne" | "find">;
|
||||||
userDAL: Pick<TUserDALFactory, "find">;
|
userDAL: Pick<TUserDALFactory, "find">;
|
||||||
secretApprovalPolicyApproverDAL: TSecretApprovalPolicyApproverDALFactory;
|
secretApprovalPolicyApproverDAL: TSecretApprovalPolicyApproverDALFactory;
|
||||||
secretApprovalPolicyBypasserDAL: TSecretApprovalPolicyBypasserDALFactory;
|
secretApprovalPolicyBypasserDAL: TSecretApprovalPolicyBypasserDALFactory;
|
||||||
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
|
||||||
secretApprovalRequestDAL: Pick<TSecretApprovalRequestDALFactory, "update">;
|
secretApprovalRequestDAL: Pick<TSecretApprovalRequestDALFactory, "update">;
|
||||||
|
secretApprovalPolicyEnvironmentDAL: TSecretApprovalPolicyEnvironmentDALFactory;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TSecretApprovalPolicyServiceFactory = ReturnType<typeof secretApprovalPolicyServiceFactory>;
|
export type TSecretApprovalPolicyServiceFactory = ReturnType<typeof secretApprovalPolicyServiceFactory>;
|
||||||
@@ -50,27 +53,30 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
permissionService,
|
permissionService,
|
||||||
secretApprovalPolicyApproverDAL,
|
secretApprovalPolicyApproverDAL,
|
||||||
secretApprovalPolicyBypasserDAL,
|
secretApprovalPolicyBypasserDAL,
|
||||||
|
secretApprovalPolicyEnvironmentDAL,
|
||||||
projectEnvDAL,
|
projectEnvDAL,
|
||||||
userDAL,
|
userDAL,
|
||||||
licenseService,
|
licenseService,
|
||||||
secretApprovalRequestDAL
|
secretApprovalRequestDAL
|
||||||
}: TSecretApprovalPolicyServiceFactoryDep) => {
|
}: TSecretApprovalPolicyServiceFactoryDep) => {
|
||||||
const $policyExists = async ({
|
const $policyExists = async ({
|
||||||
|
envIds,
|
||||||
envId,
|
envId,
|
||||||
secretPath,
|
secretPath,
|
||||||
policyId
|
policyId
|
||||||
}: {
|
}: {
|
||||||
envId: string;
|
envIds?: string[];
|
||||||
|
envId?: string;
|
||||||
secretPath: string;
|
secretPath: string;
|
||||||
policyId?: string;
|
policyId?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const policy = await secretApprovalPolicyDAL
|
if (!envIds && !envId) {
|
||||||
.findOne({
|
throw new BadRequestError({ message: "At least one environment should be provided" });
|
||||||
envId,
|
}
|
||||||
secretPath,
|
const policy = await secretApprovalPolicyDAL.findPolicyByEnvIdAndSecretPath({
|
||||||
deletedAt: null
|
envIds: envId ? [envId] : envIds || [],
|
||||||
})
|
secretPath
|
||||||
.catch(() => null);
|
});
|
||||||
|
|
||||||
return policyId ? policy && policy.id !== policyId : Boolean(policy);
|
return policyId ? policy && policy.id !== policyId : Boolean(policy);
|
||||||
};
|
};
|
||||||
@@ -87,6 +93,7 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
projectId,
|
projectId,
|
||||||
secretPath,
|
secretPath,
|
||||||
environment,
|
environment,
|
||||||
|
environments,
|
||||||
enforcementLevel,
|
enforcementLevel,
|
||||||
allowedSelfApprovals
|
allowedSelfApprovals
|
||||||
}: TCreateSapDTO) => {
|
}: TCreateSapDTO) => {
|
||||||
@@ -110,7 +117,8 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionActions.Create,
|
ProjectPermissionActions.Create,
|
||||||
@@ -125,17 +133,23 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const env = await projectEnvDAL.findOne({ slug: environment, projectId });
|
const mergedEnvs = (environment ? [environment] : environments) || [];
|
||||||
if (!env) {
|
if (mergedEnvs.length === 0) {
|
||||||
throw new NotFoundError({
|
throw new BadRequestError({ message: "Must provide either environment or environments" });
|
||||||
message: `Environment with slug '${environment}' not found in project with ID ${projectId}`
|
}
|
||||||
});
|
const envs = await projectEnvDAL.find({ $in: { slug: mergedEnvs }, projectId });
|
||||||
|
if (!envs.length || envs.length !== mergedEnvs.length) {
|
||||||
|
const notFoundEnvs = mergedEnvs.filter((env) => !envs.find((el) => el.slug === env));
|
||||||
|
throw new NotFoundError({ message: `One or more environments not found: ${notFoundEnvs.join(", ")}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await $policyExists({ envId: env.id, secretPath })) {
|
for (const env of envs) {
|
||||||
throw new BadRequestError({
|
// eslint-disable-next-line no-await-in-loop
|
||||||
message: `A policy for secret path '${secretPath}' already exists in environment '${environment}'`
|
if (await $policyExists({ envId: env.id, secretPath })) {
|
||||||
});
|
throw new BadRequestError({
|
||||||
|
message: `A policy for secret path '${secretPath}' already exists in environment '${env.slug}'`
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let groupBypassers: string[] = [];
|
let groupBypassers: string[] = [];
|
||||||
@@ -179,7 +193,7 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
const secretApproval = await secretApprovalPolicyDAL.transaction(async (tx) => {
|
const secretApproval = await secretApprovalPolicyDAL.transaction(async (tx) => {
|
||||||
const doc = await secretApprovalPolicyDAL.create(
|
const doc = await secretApprovalPolicyDAL.create(
|
||||||
{
|
{
|
||||||
envId: env.id,
|
envId: envs[0].id,
|
||||||
approvals,
|
approvals,
|
||||||
secretPath,
|
secretPath,
|
||||||
name,
|
name,
|
||||||
@@ -188,6 +202,13 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
},
|
},
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
await secretApprovalPolicyEnvironmentDAL.insertMany(
|
||||||
|
envs.map((env) => ({
|
||||||
|
envId: env.id,
|
||||||
|
policyId: doc.id
|
||||||
|
})),
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
|
||||||
let userApproverIds = userApprovers;
|
let userApproverIds = userApprovers;
|
||||||
if (userApproverNames.length) {
|
if (userApproverNames.length) {
|
||||||
@@ -251,12 +272,13 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
return doc;
|
return doc;
|
||||||
});
|
});
|
||||||
|
|
||||||
return { ...secretApproval, environment: env, projectId };
|
return { ...secretApproval, environments: envs, projectId, environment: envs[0] };
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateSecretApprovalPolicy = async ({
|
const updateSecretApprovalPolicy = async ({
|
||||||
approvers,
|
approvers,
|
||||||
bypassers,
|
bypassers,
|
||||||
|
environments,
|
||||||
secretPath,
|
secretPath,
|
||||||
name,
|
name,
|
||||||
actorId,
|
actorId,
|
||||||
@@ -286,17 +308,26 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
message: `Secret approval policy with ID '${secretPolicyId}' not found`
|
message: `Secret approval policy with ID '${secretPolicyId}' not found`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
let envs = secretApprovalPolicy.environments;
|
||||||
if (
|
if (
|
||||||
await $policyExists({
|
environments &&
|
||||||
envId: secretApprovalPolicy.envId,
|
(environments.length !== envs.length || environments.some((env) => !envs.find((el) => el.slug === env)))
|
||||||
secretPath: secretPath || secretApprovalPolicy.secretPath,
|
|
||||||
policyId: secretApprovalPolicy.id
|
|
||||||
})
|
|
||||||
) {
|
) {
|
||||||
throw new BadRequestError({
|
envs = await projectEnvDAL.find({ $in: { slug: environments }, projectId: secretApprovalPolicy.projectId });
|
||||||
message: `A policy for secret path '${secretPath}' already exists in environment '${secretApprovalPolicy.environment.slug}'`
|
}
|
||||||
});
|
for (const env of envs) {
|
||||||
|
if (
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await $policyExists({
|
||||||
|
envId: env.id,
|
||||||
|
secretPath: secretPath || secretApprovalPolicy.secretPath,
|
||||||
|
policyId: secretApprovalPolicy.id
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `A policy for secret path '${secretPath || secretApprovalPolicy.secretPath}' already exists in environment '${env.slug}'`
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { permission } = await permissionService.getProjectPermission({
|
const { permission } = await permissionService.getProjectPermission({
|
||||||
@@ -304,7 +335,8 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: secretApprovalPolicy.projectId,
|
projectId: secretApprovalPolicy.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SecretApproval);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SecretApproval);
|
||||||
|
|
||||||
@@ -412,6 +444,17 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (environments) {
|
||||||
|
await secretApprovalPolicyEnvironmentDAL.delete({ policyId: doc.id }, tx);
|
||||||
|
await secretApprovalPolicyEnvironmentDAL.insertMany(
|
||||||
|
envs.map((env) => ({
|
||||||
|
envId: env.id,
|
||||||
|
policyId: doc.id
|
||||||
|
})),
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await secretApprovalPolicyBypasserDAL.delete({ policyId: doc.id }, tx);
|
await secretApprovalPolicyBypasserDAL.delete({ policyId: doc.id }, tx);
|
||||||
|
|
||||||
if (bypasserUserIds.length) {
|
if (bypasserUserIds.length) {
|
||||||
@@ -438,7 +481,8 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
...updatedSap,
|
...updatedSap,
|
||||||
environment: secretApprovalPolicy.environment,
|
environments: secretApprovalPolicy.environments,
|
||||||
|
environment: secretApprovalPolicy.environments[0],
|
||||||
projectId: secretApprovalPolicy.projectId
|
projectId: secretApprovalPolicy.projectId
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -459,7 +503,8 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: sapPolicy.projectId,
|
projectId: sapPolicy.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionActions.Delete,
|
ProjectPermissionActions.Delete,
|
||||||
@@ -483,7 +528,12 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
const updatedPolicy = await secretApprovalPolicyDAL.softDeleteById(secretPolicyId, tx);
|
const updatedPolicy = await secretApprovalPolicyDAL.softDeleteById(secretPolicyId, tx);
|
||||||
return updatedPolicy;
|
return updatedPolicy;
|
||||||
});
|
});
|
||||||
return { ...deletedPolicy, projectId: sapPolicy.projectId, environment: sapPolicy.environment };
|
return {
|
||||||
|
...deletedPolicy,
|
||||||
|
projectId: sapPolicy.projectId,
|
||||||
|
environments: sapPolicy.environments,
|
||||||
|
environment: sapPolicy.environments[0]
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSecretApprovalPolicyByProjectId = async ({
|
const getSecretApprovalPolicyByProjectId = async ({
|
||||||
@@ -498,7 +548,8 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval);
|
||||||
|
|
||||||
@@ -515,7 +566,7 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const policies = await secretApprovalPolicyDAL.find({ envId: env.id, deletedAt: null });
|
const policies = await secretApprovalPolicyDAL.find({ deletedAt: null }, { envId: env.id });
|
||||||
if (!policies.length) return;
|
if (!policies.length) return;
|
||||||
// this will filter policies either without scoped to secret path or the one that matches with secret path
|
// this will filter policies either without scoped to secret path or the one that matches with secret path
|
||||||
const policiesFilteredByPath = policies.filter(
|
const policiesFilteredByPath = policies.filter(
|
||||||
@@ -542,7 +593,8 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
return getSecretApprovalPolicy(projectId, environment, secretPath);
|
return getSecretApprovalPolicy(projectId, environment, secretPath);
|
||||||
@@ -568,7 +620,8 @@ export const secretApprovalPolicyServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: sapPolicy.projectId,
|
projectId: sapPolicy.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretApproval);
|
||||||
|
@@ -5,7 +5,8 @@ import { ApproverType, BypasserType } from "../access-approval-policy/access-app
|
|||||||
export type TCreateSapDTO = {
|
export type TCreateSapDTO = {
|
||||||
approvals: number;
|
approvals: number;
|
||||||
secretPath: string;
|
secretPath: string;
|
||||||
environment: string;
|
environment?: string;
|
||||||
|
environments?: string[];
|
||||||
approvers: ({ type: ApproverType.Group; id: string } | { type: ApproverType.User; id?: string; username?: string })[];
|
approvers: ({ type: ApproverType.Group; id: string } | { type: ApproverType.User; id?: string; username?: string })[];
|
||||||
bypassers?: (
|
bypassers?: (
|
||||||
| { type: BypasserType.Group; id: string }
|
| { type: BypasserType.Group; id: string }
|
||||||
@@ -29,6 +30,7 @@ export type TUpdateSapDTO = {
|
|||||||
name?: string;
|
name?: string;
|
||||||
enforcementLevel?: EnforcementLevel;
|
enforcementLevel?: EnforcementLevel;
|
||||||
allowedSelfApprovals?: boolean;
|
allowedSelfApprovals?: boolean;
|
||||||
|
environments?: string[];
|
||||||
} & Omit<TProjectPermission, "projectId">;
|
} & Omit<TProjectPermission, "projectId">;
|
||||||
|
|
||||||
export type TDeleteSapDTO = {
|
export type TDeleteSapDTO = {
|
||||||
|
@@ -40,6 +40,13 @@ export const secretApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
`${TableName.SecretApprovalRequest}.policyId`,
|
`${TableName.SecretApprovalRequest}.policyId`,
|
||||||
`${TableName.SecretApprovalPolicy}.id`
|
`${TableName.SecretApprovalPolicy}.id`
|
||||||
)
|
)
|
||||||
|
.leftJoin(TableName.SecretApprovalPolicyEnvironment, (bd) => {
|
||||||
|
bd.on(
|
||||||
|
`${TableName.SecretApprovalPolicy}.id`,
|
||||||
|
"=",
|
||||||
|
`${TableName.SecretApprovalPolicyEnvironment}.policyId`
|
||||||
|
).andOn(`${TableName.SecretApprovalPolicyEnvironment}.envId`, "=", `${TableName.SecretFolder}.envId`);
|
||||||
|
})
|
||||||
.leftJoin<TUsers>(
|
.leftJoin<TUsers>(
|
||||||
db(TableName.Users).as("statusChangedByUser"),
|
db(TableName.Users).as("statusChangedByUser"),
|
||||||
`${TableName.SecretApprovalRequest}.statusChangedByUserId`,
|
`${TableName.SecretApprovalRequest}.statusChangedByUserId`,
|
||||||
@@ -146,7 +153,7 @@ export const secretApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
tx.ref("projectId").withSchema(TableName.Environment),
|
tx.ref("projectId").withSchema(TableName.Environment),
|
||||||
tx.ref("slug").withSchema(TableName.Environment).as("environment"),
|
tx.ref("slug").withSchema(TableName.Environment).as("environment"),
|
||||||
tx.ref("secretPath").withSchema(TableName.SecretApprovalPolicy).as("policySecretPath"),
|
tx.ref("secretPath").withSchema(TableName.SecretApprovalPolicy).as("policySecretPath"),
|
||||||
tx.ref("envId").withSchema(TableName.SecretApprovalPolicy).as("policyEnvId"),
|
tx.ref("envId").withSchema(TableName.SecretApprovalPolicyEnvironment).as("policyEnvId"),
|
||||||
tx.ref("enforcementLevel").withSchema(TableName.SecretApprovalPolicy).as("policyEnforcementLevel"),
|
tx.ref("enforcementLevel").withSchema(TableName.SecretApprovalPolicy).as("policyEnforcementLevel"),
|
||||||
tx.ref("allowedSelfApprovals").withSchema(TableName.SecretApprovalPolicy).as("policyAllowedSelfApprovals"),
|
tx.ref("allowedSelfApprovals").withSchema(TableName.SecretApprovalPolicy).as("policyAllowedSelfApprovals"),
|
||||||
tx.ref("approvals").withSchema(TableName.SecretApprovalPolicy).as("policyApprovals"),
|
tx.ref("approvals").withSchema(TableName.SecretApprovalPolicy).as("policyApprovals"),
|
||||||
|
@@ -36,7 +36,7 @@ export const sendApprovalEmailsFn = async ({
|
|||||||
firstName: reviewerUser.firstName,
|
firstName: reviewerUser.firstName,
|
||||||
projectName: project.name,
|
projectName: project.name,
|
||||||
organizationName: project.organization.name,
|
organizationName: project.organization.name,
|
||||||
approvalUrl: `${cfg.SITE_URL}/projects/${project.id}/secret-manager/approval?requestId=${secretApprovalRequest.id}`
|
approvalUrl: `${cfg.SITE_URL}/projects/secret-management/${project.id}/approval?requestId=${secretApprovalRequest.id}`
|
||||||
},
|
},
|
||||||
template: SmtpTemplates.SecretApprovalRequestNeedsReview
|
template: SmtpTemplates.SecretApprovalRequestNeedsReview
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
/* eslint-disable no-nested-ternary */
|
/* eslint-disable no-nested-ternary */
|
||||||
import { ForbiddenError, subject } from "@casl/ability";
|
import { ForbiddenError, subject } from "@casl/ability";
|
||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ActionProjectType,
|
||||||
ProjectMembershipRole,
|
ProjectMembershipRole,
|
||||||
SecretEncryptionAlgo,
|
SecretEncryptionAlgo,
|
||||||
SecretKeyEncoding,
|
SecretKeyEncoding,
|
||||||
@@ -67,6 +69,7 @@ import { throwIfMissingSecretReadValueOrDescribePermission } from "../permission
|
|||||||
import { TPermissionServiceFactory } from "../permission/permission-service-types";
|
import { TPermissionServiceFactory } from "../permission/permission-service-types";
|
||||||
import { ProjectPermissionSecretActions, ProjectPermissionSub } from "../permission/project-permission";
|
import { ProjectPermissionSecretActions, ProjectPermissionSub } from "../permission/project-permission";
|
||||||
import { TSecretApprovalPolicyDALFactory } from "../secret-approval-policy/secret-approval-policy-dal";
|
import { TSecretApprovalPolicyDALFactory } from "../secret-approval-policy/secret-approval-policy-dal";
|
||||||
|
import { scanSecretPolicyViolations } from "../secret-scanning-v2/secret-scanning-v2-fns";
|
||||||
import { TSecretSnapshotServiceFactory } from "../secret-snapshot/secret-snapshot-service";
|
import { TSecretSnapshotServiceFactory } from "../secret-snapshot/secret-snapshot-service";
|
||||||
import { TSecretApprovalRequestDALFactory } from "./secret-approval-request-dal";
|
import { TSecretApprovalRequestDALFactory } from "./secret-approval-request-dal";
|
||||||
import { sendApprovalEmailsFn } from "./secret-approval-request-fns";
|
import { sendApprovalEmailsFn } from "./secret-approval-request-fns";
|
||||||
@@ -183,7 +186,8 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const count = await secretApprovalRequestDAL.findProjectRequestCount(projectId, actorId, policyId);
|
const count = await secretApprovalRequestDAL.findProjectRequestCount(projectId, actorId, policyId);
|
||||||
@@ -210,7 +214,8 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const { shouldUseSecretV2Bridge } = await projectBotService.getBotKey(projectId);
|
const { shouldUseSecretV2Bridge } = await projectBotService.getBotKey(projectId);
|
||||||
@@ -262,7 +267,8 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
if (
|
if (
|
||||||
!hasRole(ProjectMembershipRole.Admin) &&
|
!hasRole(ProjectMembershipRole.Admin) &&
|
||||||
@@ -411,7 +417,8 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: secretApprovalRequest.projectId,
|
projectId: secretApprovalRequest.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
if (
|
if (
|
||||||
!hasRole(ProjectMembershipRole.Admin) &&
|
!hasRole(ProjectMembershipRole.Admin) &&
|
||||||
@@ -480,7 +487,8 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: secretApprovalRequest.projectId,
|
projectId: secretApprovalRequest.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
if (
|
if (
|
||||||
!hasRole(ProjectMembershipRole.Admin) &&
|
!hasRole(ProjectMembershipRole.Admin) &&
|
||||||
@@ -530,13 +538,19 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
message: "The policy associated with this secret approval request has been deleted."
|
message: "The policy associated with this secret approval request has been deleted."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!policy.envId) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: "The policy associated with this secret approval request is not linked to the environment."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const { hasRole } = await permissionService.getProjectPermission({
|
const { hasRole } = await permissionService.getProjectPermission({
|
||||||
actor: ActorType.USER,
|
actor: ActorType.USER,
|
||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -954,7 +968,7 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
bypassReason,
|
bypassReason,
|
||||||
secretPath: policy.secretPath,
|
secretPath: policy.secretPath,
|
||||||
environment: env.name,
|
environment: env.name,
|
||||||
approvalUrl: `${cfg.SITE_URL}/projects/${project.id}/secret-manager/approval`
|
approvalUrl: `${cfg.SITE_URL}/projects/secret-management/${project.id}/approval`
|
||||||
},
|
},
|
||||||
template: SmtpTemplates.AccessSecretRequestBypassed
|
template: SmtpTemplates.AccessSecretRequestBypassed
|
||||||
});
|
});
|
||||||
@@ -1088,7 +1102,8 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
throwIfMissingSecretReadValueOrDescribePermission(permission, ProjectPermissionSecretActions.ReadValue, {
|
throwIfMissingSecretReadValueOrDescribePermission(permission, ProjectPermissionSecretActions.ReadValue, {
|
||||||
@@ -1368,8 +1383,9 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
policy,
|
policy,
|
||||||
projectId,
|
projectId,
|
||||||
secretPath,
|
secretPath,
|
||||||
environment
|
environment,
|
||||||
}: TGenerateSecretApprovalRequestV2BridgeDTO) => {
|
trx: providedTx
|
||||||
|
}: TGenerateSecretApprovalRequestV2BridgeDTO & { trx?: Knex }) => {
|
||||||
if (actor === ActorType.SERVICE || actor === ActorType.Machine)
|
if (actor === ActorType.SERVICE || actor === ActorType.Machine)
|
||||||
throw new BadRequestError({ message: "Cannot use service token or machine token over protected branches" });
|
throw new BadRequestError({ message: "Cannot use service token or machine token over protected branches" });
|
||||||
|
|
||||||
@@ -1378,7 +1394,8 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
const folder = await folderDAL.findBySecretPath(projectId, environment, secretPath);
|
const folder = await folderDAL.findBySecretPath(projectId, environment, secretPath);
|
||||||
if (!folder)
|
if (!folder)
|
||||||
@@ -1396,6 +1413,20 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const project = await projectDAL.findById(projectId);
|
||||||
|
await scanSecretPolicyViolations(
|
||||||
|
projectId,
|
||||||
|
secretPath,
|
||||||
|
[
|
||||||
|
...(data[SecretOperations.Create] || []),
|
||||||
|
...(data[SecretOperations.Update] || []).filter((el) => el.secretValue)
|
||||||
|
].map((el) => ({
|
||||||
|
secretKey: el.secretKey,
|
||||||
|
secretValue: el.secretValue as string
|
||||||
|
})),
|
||||||
|
project.secretDetectionIgnoreValues || []
|
||||||
|
);
|
||||||
|
|
||||||
// for created secret approval change
|
// for created secret approval change
|
||||||
const createdSecrets = data[SecretOperations.Create];
|
const createdSecrets = data[SecretOperations.Create];
|
||||||
if (createdSecrets && createdSecrets?.length) {
|
if (createdSecrets && createdSecrets?.length) {
|
||||||
@@ -1595,7 +1626,7 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const secretApprovalRequest = await secretApprovalRequestDAL.transaction(async (tx) => {
|
const executeApprovalRequestCreation = async (tx: Knex) => {
|
||||||
const doc = await secretApprovalRequestDAL.create(
|
const doc = await secretApprovalRequestDAL.create(
|
||||||
{
|
{
|
||||||
folderId,
|
folderId,
|
||||||
@@ -1657,7 +1688,11 @@ export const secretApprovalRequestServiceFactory = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return { ...doc, commits: approvalCommits };
|
return { ...doc, commits: approvalCommits };
|
||||||
});
|
};
|
||||||
|
|
||||||
|
const secretApprovalRequest = providedTx
|
||||||
|
? await executeApprovalRequestCreation(providedTx)
|
||||||
|
: await secretApprovalRequestDAL.transaction(executeApprovalRequestCreation);
|
||||||
|
|
||||||
const user = await userDAL.findById(actorId);
|
const user = await userDAL.findById(actorId);
|
||||||
const env = await projectEnvDAL.findOne({ id: policy.envId });
|
const env = await projectEnvDAL.findOne({ id: policy.envId });
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
export * from "./okta-client-secret-rotation-constants";
|
||||||
|
export * from "./okta-client-secret-rotation-schemas";
|
||||||
|
export * from "./okta-client-secret-rotation-types";
|
@@ -0,0 +1,15 @@
|
|||||||
|
import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
|
||||||
|
import { TSecretRotationV2ListItem } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";
|
||||||
|
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||||
|
|
||||||
|
export const OKTA_CLIENT_SECRET_ROTATION_LIST_OPTION: TSecretRotationV2ListItem = {
|
||||||
|
name: "Okta Client Secret",
|
||||||
|
type: SecretRotation.OktaClientSecret,
|
||||||
|
connection: AppConnection.Okta,
|
||||||
|
template: {
|
||||||
|
secretsMapping: {
|
||||||
|
clientId: "OKTA_CLIENT_ID",
|
||||||
|
clientSecret: "OKTA_CLIENT_SECRET"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
@@ -0,0 +1,273 @@
|
|||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
|
import { AxiosError } from "axios";
|
||||||
|
|
||||||
|
import {
|
||||||
|
TRotationFactory,
|
||||||
|
TRotationFactoryGetSecretsPayload,
|
||||||
|
TRotationFactoryIssueCredentials,
|
||||||
|
TRotationFactoryRevokeCredentials,
|
||||||
|
TRotationFactoryRotateCredentials
|
||||||
|
} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";
|
||||||
|
import { request } from "@app/lib/config/request";
|
||||||
|
import { delay as delayMs } from "@app/lib/delay";
|
||||||
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
|
import { getOktaInstanceUrl } from "@app/services/app-connection/okta";
|
||||||
|
|
||||||
|
import {
|
||||||
|
TOktaClientSecret,
|
||||||
|
TOktaClientSecretRotationGeneratedCredentials,
|
||||||
|
TOktaClientSecretRotationWithConnection
|
||||||
|
} from "./okta-client-secret-rotation-types";
|
||||||
|
|
||||||
|
type OktaErrorResponse = { errorCode: string; errorSummary: string; errorCauses?: { errorSummary: string }[] };
|
||||||
|
|
||||||
|
const isOktaErrorResponse = (data: unknown): data is OktaErrorResponse => {
|
||||||
|
return (
|
||||||
|
typeof data === "object" &&
|
||||||
|
data !== null &&
|
||||||
|
"errorSummary" in data &&
|
||||||
|
typeof (data as OktaErrorResponse).errorSummary === "string"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const createErrorMessage = (error: unknown) => {
|
||||||
|
if (error instanceof AxiosError) {
|
||||||
|
if (error.response?.data && isOktaErrorResponse(error.response.data)) {
|
||||||
|
const oktaError = error.response.data;
|
||||||
|
if (oktaError.errorCauses && oktaError.errorCauses.length > 0) {
|
||||||
|
return oktaError.errorCauses[0].errorSummary;
|
||||||
|
}
|
||||||
|
return oktaError.errorSummary;
|
||||||
|
}
|
||||||
|
if (error.message) {
|
||||||
|
return error.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "Unknown error";
|
||||||
|
};
|
||||||
|
|
||||||
|
// Delay between each revocation call in revokeCredentials
|
||||||
|
const DELAY_MS = 1000;
|
||||||
|
|
||||||
|
export const oktaClientSecretRotationFactory: TRotationFactory<
|
||||||
|
TOktaClientSecretRotationWithConnection,
|
||||||
|
TOktaClientSecretRotationGeneratedCredentials
|
||||||
|
> = (secretRotation) => {
|
||||||
|
const {
|
||||||
|
connection,
|
||||||
|
parameters: { clientId },
|
||||||
|
secretsMapping
|
||||||
|
} = secretRotation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new client secret for the Okta app.
|
||||||
|
*/
|
||||||
|
const $rotateClientSecret = async () => {
|
||||||
|
const instanceUrl = await getOktaInstanceUrl(connection);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data } = await request.post<TOktaClientSecret>(
|
||||||
|
`${instanceUrl}/api/v1/apps/${clientId}/credentials/secrets`,
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json",
|
||||||
|
Authorization: `SSWS ${connection.credentials.apiToken}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!data.client_secret || !data.id) {
|
||||||
|
throw new Error("Invalid response from Okta: missing 'client_secret' or secret 'id'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
clientSecret: data.client_secret,
|
||||||
|
secretId: data.id,
|
||||||
|
clientId
|
||||||
|
};
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (
|
||||||
|
error instanceof AxiosError &&
|
||||||
|
error.response?.data &&
|
||||||
|
isOktaErrorResponse(error.response.data) &&
|
||||||
|
error.response.data.errorCode === "E0000001"
|
||||||
|
) {
|
||||||
|
// Okta has a maximum of 2 secrets per app, thus we must warn the users in case they already have 2
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `Failed to add client secret to Okta app ${clientId}: You must have only a single secret for the Okta app prior to creating this secret rotation.`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `Failed to add client secret to Okta app ${clientId}: ${createErrorMessage(error)}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List client secrets.
|
||||||
|
*/
|
||||||
|
const $listClientSecrets = async () => {
|
||||||
|
const instanceUrl = await getOktaInstanceUrl(connection);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data } = await request.get<TOktaClientSecret[]>(
|
||||||
|
`${instanceUrl}/api/v1/apps/${clientId}/credentials/secrets`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json",
|
||||||
|
Authorization: `SSWS ${connection.credentials.apiToken}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
} catch (error: unknown) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `Failed to list client secrets for Okta app ${clientId}: ${createErrorMessage(error)}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a credential with the given secretId exists.
|
||||||
|
*/
|
||||||
|
const credentialExists = async (secretId: string): Promise<boolean> => {
|
||||||
|
const instanceUrl = await getOktaInstanceUrl(connection);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data } = await request.get<TOktaClientSecret>(
|
||||||
|
`${instanceUrl}/api/v1/apps/${clientId}/credentials/secrets/${secretId}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json",
|
||||||
|
Authorization: `SSWS ${connection.credentials.apiToken}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return data.id === secretId;
|
||||||
|
} catch (_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Revokes a client secret from the Okta app using its secretId.
|
||||||
|
* First checks if the credential exists before attempting revocation.
|
||||||
|
*/
|
||||||
|
const revokeCredential = async (secretId: string) => {
|
||||||
|
// Check if credential exists before attempting revocation
|
||||||
|
const exists = await credentialExists(secretId);
|
||||||
|
if (!exists) {
|
||||||
|
return; // Credential doesn't exist, nothing to revoke
|
||||||
|
}
|
||||||
|
|
||||||
|
const instanceUrl = await getOktaInstanceUrl(connection);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// First deactivate the secret
|
||||||
|
await request.post(
|
||||||
|
`${instanceUrl}/api/v1/apps/${clientId}/credentials/secrets/${secretId}/lifecycle/deactivate`,
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `SSWS ${connection.credentials.apiToken}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Then delete it
|
||||||
|
await request.delete(`${instanceUrl}/api/v1/apps/${clientId}/credentials/secrets/${secretId}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `SSWS ${connection.credentials.apiToken}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (
|
||||||
|
error instanceof AxiosError &&
|
||||||
|
error.response?.data &&
|
||||||
|
isOktaErrorResponse(error.response.data) &&
|
||||||
|
error.response.data.errorCode === "E0000001"
|
||||||
|
) {
|
||||||
|
// If this is the last secret, we cannot revoke it
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `Failed to remove client secret with secretId ${secretId} from app ${clientId}: ${createErrorMessage(error)}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Issues a new set of credentials.
|
||||||
|
*/
|
||||||
|
const issueCredentials: TRotationFactoryIssueCredentials<TOktaClientSecretRotationGeneratedCredentials> = async (
|
||||||
|
callback
|
||||||
|
) => {
|
||||||
|
const credentials = await $rotateClientSecret();
|
||||||
|
return callback(credentials);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Revokes a list of credentials.
|
||||||
|
*/
|
||||||
|
const revokeCredentials: TRotationFactoryRevokeCredentials<TOktaClientSecretRotationGeneratedCredentials> = async (
|
||||||
|
credentials,
|
||||||
|
callback
|
||||||
|
) => {
|
||||||
|
if (!credentials?.length) return callback();
|
||||||
|
|
||||||
|
for (const { secretId } of credentials) {
|
||||||
|
await revokeCredential(secretId);
|
||||||
|
await delayMs(DELAY_MS);
|
||||||
|
}
|
||||||
|
return callback();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates credentials by issuing new ones and revoking the old.
|
||||||
|
*/
|
||||||
|
const rotateCredentials: TRotationFactoryRotateCredentials<TOktaClientSecretRotationGeneratedCredentials> = async (
|
||||||
|
oldCredentials,
|
||||||
|
callback,
|
||||||
|
activeCredentials
|
||||||
|
) => {
|
||||||
|
// Since in Okta you can only have a maximum of 2 secrets at a time, we must delete any other secret besides the current one PRIOR to generating the second secret
|
||||||
|
if (oldCredentials?.secretId) {
|
||||||
|
await revokeCredential(oldCredentials.secretId);
|
||||||
|
} else if (activeCredentials) {
|
||||||
|
// On the first rotation oldCredentials won't be set so we must find the second secret manually
|
||||||
|
const secrets = await $listClientSecrets();
|
||||||
|
|
||||||
|
if (secrets.length > 1) {
|
||||||
|
const nonActiveSecret = secrets.find((secret) => secret.id !== activeCredentials.secretId);
|
||||||
|
if (nonActiveSecret) {
|
||||||
|
await revokeCredential(nonActiveSecret.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const newCredentials = await $rotateClientSecret();
|
||||||
|
return callback(newCredentials);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the generated credentials into the secret payload format.
|
||||||
|
*/
|
||||||
|
const getSecretsPayload: TRotationFactoryGetSecretsPayload<TOktaClientSecretRotationGeneratedCredentials> = ({
|
||||||
|
clientSecret
|
||||||
|
}) => [
|
||||||
|
{ key: secretsMapping.clientId, value: clientId },
|
||||||
|
{ key: secretsMapping.clientSecret, value: clientSecret }
|
||||||
|
];
|
||||||
|
|
||||||
|
return {
|
||||||
|
issueCredentials,
|
||||||
|
revokeCredentials,
|
||||||
|
rotateCredentials,
|
||||||
|
getSecretsPayload
|
||||||
|
};
|
||||||
|
};
|
@@ -0,0 +1,68 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { SecretRotation } from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-enums";
|
||||||
|
import {
|
||||||
|
BaseCreateSecretRotationSchema,
|
||||||
|
BaseSecretRotationSchema,
|
||||||
|
BaseUpdateSecretRotationSchema
|
||||||
|
} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-schemas";
|
||||||
|
import { SecretRotations } from "@app/lib/api-docs";
|
||||||
|
import { SecretNameSchema } from "@app/server/lib/schemas";
|
||||||
|
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||||
|
|
||||||
|
export const OktaClientSecretRotationGeneratedCredentialsSchema = z
|
||||||
|
.object({
|
||||||
|
clientId: z.string(),
|
||||||
|
clientSecret: z.string(),
|
||||||
|
secretId: z.string()
|
||||||
|
})
|
||||||
|
.array()
|
||||||
|
.min(1)
|
||||||
|
.max(2);
|
||||||
|
|
||||||
|
const OktaClientSecretRotationParametersSchema = z.object({
|
||||||
|
clientId: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.min(1, "Client ID Required")
|
||||||
|
.describe(SecretRotations.PARAMETERS.OKTA_CLIENT_SECRET.clientId)
|
||||||
|
});
|
||||||
|
|
||||||
|
const OktaClientSecretRotationSecretsMappingSchema = z.object({
|
||||||
|
clientId: SecretNameSchema.describe(SecretRotations.SECRETS_MAPPING.OKTA_CLIENT_SECRET.clientId),
|
||||||
|
clientSecret: SecretNameSchema.describe(SecretRotations.SECRETS_MAPPING.OKTA_CLIENT_SECRET.clientSecret)
|
||||||
|
});
|
||||||
|
|
||||||
|
export const OktaClientSecretRotationTemplateSchema = z.object({
|
||||||
|
secretsMapping: z.object({
|
||||||
|
clientId: z.string(),
|
||||||
|
clientSecret: z.string()
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
export const OktaClientSecretRotationSchema = BaseSecretRotationSchema(SecretRotation.OktaClientSecret).extend({
|
||||||
|
type: z.literal(SecretRotation.OktaClientSecret),
|
||||||
|
parameters: OktaClientSecretRotationParametersSchema,
|
||||||
|
secretsMapping: OktaClientSecretRotationSecretsMappingSchema
|
||||||
|
});
|
||||||
|
|
||||||
|
export const CreateOktaClientSecretRotationSchema = BaseCreateSecretRotationSchema(
|
||||||
|
SecretRotation.OktaClientSecret
|
||||||
|
).extend({
|
||||||
|
parameters: OktaClientSecretRotationParametersSchema,
|
||||||
|
secretsMapping: OktaClientSecretRotationSecretsMappingSchema
|
||||||
|
});
|
||||||
|
|
||||||
|
export const UpdateOktaClientSecretRotationSchema = BaseUpdateSecretRotationSchema(
|
||||||
|
SecretRotation.OktaClientSecret
|
||||||
|
).extend({
|
||||||
|
parameters: OktaClientSecretRotationParametersSchema.optional(),
|
||||||
|
secretsMapping: OktaClientSecretRotationSecretsMappingSchema.optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const OktaClientSecretRotationListItemSchema = z.object({
|
||||||
|
name: z.literal("Okta Client Secret"),
|
||||||
|
connection: z.literal(AppConnection.Okta),
|
||||||
|
type: z.literal(SecretRotation.OktaClientSecret),
|
||||||
|
template: OktaClientSecretRotationTemplateSchema
|
||||||
|
});
|
@@ -0,0 +1,40 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { TOktaConnection } from "@app/services/app-connection/okta";
|
||||||
|
|
||||||
|
import {
|
||||||
|
CreateOktaClientSecretRotationSchema,
|
||||||
|
OktaClientSecretRotationGeneratedCredentialsSchema,
|
||||||
|
OktaClientSecretRotationListItemSchema,
|
||||||
|
OktaClientSecretRotationSchema
|
||||||
|
} from "./okta-client-secret-rotation-schemas";
|
||||||
|
|
||||||
|
export type TOktaClientSecretRotation = z.infer<typeof OktaClientSecretRotationSchema>;
|
||||||
|
|
||||||
|
export type TOktaClientSecretRotationInput = z.infer<typeof CreateOktaClientSecretRotationSchema>;
|
||||||
|
|
||||||
|
export type TOktaClientSecretRotationListItem = z.infer<typeof OktaClientSecretRotationListItemSchema>;
|
||||||
|
|
||||||
|
export type TOktaClientSecretRotationWithConnection = TOktaClientSecretRotation & {
|
||||||
|
connection: TOktaConnection;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TOktaClientSecretRotationGeneratedCredentials = z.infer<
|
||||||
|
typeof OktaClientSecretRotationGeneratedCredentialsSchema
|
||||||
|
>;
|
||||||
|
|
||||||
|
export interface TOktaClientSecretRotationParameters {
|
||||||
|
clientId: string;
|
||||||
|
secretId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TOktaClientSecretRotationSecretsMapping {
|
||||||
|
clientId: string;
|
||||||
|
clientSecret: string;
|
||||||
|
secretId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TOktaClientSecret {
|
||||||
|
id: string;
|
||||||
|
client_secret: string;
|
||||||
|
}
|
@@ -6,7 +6,8 @@ export enum SecretRotation {
|
|||||||
Auth0ClientSecret = "auth0-client-secret",
|
Auth0ClientSecret = "auth0-client-secret",
|
||||||
AzureClientSecret = "azure-client-secret",
|
AzureClientSecret = "azure-client-secret",
|
||||||
AwsIamUserSecret = "aws-iam-user-secret",
|
AwsIamUserSecret = "aws-iam-user-secret",
|
||||||
LdapPassword = "ldap-password"
|
LdapPassword = "ldap-password",
|
||||||
|
OktaClientSecret = "okta-client-secret"
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SecretRotationStatus {
|
export enum SecretRotationStatus {
|
||||||
|
@@ -10,6 +10,7 @@ import { AZURE_CLIENT_SECRET_ROTATION_LIST_OPTION } from "./azure-client-secret"
|
|||||||
import { LDAP_PASSWORD_ROTATION_LIST_OPTION, TLdapPasswordRotation } from "./ldap-password";
|
import { LDAP_PASSWORD_ROTATION_LIST_OPTION, TLdapPasswordRotation } from "./ldap-password";
|
||||||
import { MSSQL_CREDENTIALS_ROTATION_LIST_OPTION } from "./mssql-credentials";
|
import { MSSQL_CREDENTIALS_ROTATION_LIST_OPTION } from "./mssql-credentials";
|
||||||
import { MYSQL_CREDENTIALS_ROTATION_LIST_OPTION } from "./mysql-credentials";
|
import { MYSQL_CREDENTIALS_ROTATION_LIST_OPTION } from "./mysql-credentials";
|
||||||
|
import { OKTA_CLIENT_SECRET_ROTATION_LIST_OPTION } from "./okta-client-secret";
|
||||||
import { ORACLEDB_CREDENTIALS_ROTATION_LIST_OPTION } from "./oracledb-credentials";
|
import { ORACLEDB_CREDENTIALS_ROTATION_LIST_OPTION } from "./oracledb-credentials";
|
||||||
import { POSTGRES_CREDENTIALS_ROTATION_LIST_OPTION } from "./postgres-credentials";
|
import { POSTGRES_CREDENTIALS_ROTATION_LIST_OPTION } from "./postgres-credentials";
|
||||||
import { SecretRotation, SecretRotationStatus } from "./secret-rotation-v2-enums";
|
import { SecretRotation, SecretRotationStatus } from "./secret-rotation-v2-enums";
|
||||||
@@ -30,7 +31,8 @@ const SECRET_ROTATION_LIST_OPTIONS: Record<SecretRotation, TSecretRotationV2List
|
|||||||
[SecretRotation.Auth0ClientSecret]: AUTH0_CLIENT_SECRET_ROTATION_LIST_OPTION,
|
[SecretRotation.Auth0ClientSecret]: AUTH0_CLIENT_SECRET_ROTATION_LIST_OPTION,
|
||||||
[SecretRotation.AzureClientSecret]: AZURE_CLIENT_SECRET_ROTATION_LIST_OPTION,
|
[SecretRotation.AzureClientSecret]: AZURE_CLIENT_SECRET_ROTATION_LIST_OPTION,
|
||||||
[SecretRotation.AwsIamUserSecret]: AWS_IAM_USER_SECRET_ROTATION_LIST_OPTION,
|
[SecretRotation.AwsIamUserSecret]: AWS_IAM_USER_SECRET_ROTATION_LIST_OPTION,
|
||||||
[SecretRotation.LdapPassword]: LDAP_PASSWORD_ROTATION_LIST_OPTION
|
[SecretRotation.LdapPassword]: LDAP_PASSWORD_ROTATION_LIST_OPTION,
|
||||||
|
[SecretRotation.OktaClientSecret]: OKTA_CLIENT_SECRET_ROTATION_LIST_OPTION
|
||||||
};
|
};
|
||||||
|
|
||||||
export const listSecretRotationOptions = () => {
|
export const listSecretRotationOptions = () => {
|
||||||
|
@@ -9,7 +9,8 @@ export const SECRET_ROTATION_NAME_MAP: Record<SecretRotation, string> = {
|
|||||||
[SecretRotation.Auth0ClientSecret]: "Auth0 Client Secret",
|
[SecretRotation.Auth0ClientSecret]: "Auth0 Client Secret",
|
||||||
[SecretRotation.AzureClientSecret]: "Azure Client Secret",
|
[SecretRotation.AzureClientSecret]: "Azure Client Secret",
|
||||||
[SecretRotation.AwsIamUserSecret]: "AWS IAM User Secret",
|
[SecretRotation.AwsIamUserSecret]: "AWS IAM User Secret",
|
||||||
[SecretRotation.LdapPassword]: "LDAP Password"
|
[SecretRotation.LdapPassword]: "LDAP Password",
|
||||||
|
[SecretRotation.OktaClientSecret]: "Okta Client Secret"
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SECRET_ROTATION_CONNECTION_MAP: Record<SecretRotation, AppConnection> = {
|
export const SECRET_ROTATION_CONNECTION_MAP: Record<SecretRotation, AppConnection> = {
|
||||||
@@ -20,5 +21,6 @@ export const SECRET_ROTATION_CONNECTION_MAP: Record<SecretRotation, AppConnectio
|
|||||||
[SecretRotation.Auth0ClientSecret]: AppConnection.Auth0,
|
[SecretRotation.Auth0ClientSecret]: AppConnection.Auth0,
|
||||||
[SecretRotation.AzureClientSecret]: AppConnection.AzureClientSecrets,
|
[SecretRotation.AzureClientSecret]: AppConnection.AzureClientSecrets,
|
||||||
[SecretRotation.AwsIamUserSecret]: AppConnection.AWS,
|
[SecretRotation.AwsIamUserSecret]: AppConnection.AWS,
|
||||||
[SecretRotation.LdapPassword]: AppConnection.LDAP
|
[SecretRotation.LdapPassword]: AppConnection.LDAP,
|
||||||
|
[SecretRotation.OktaClientSecret]: AppConnection.Okta
|
||||||
};
|
};
|
||||||
|
@@ -167,7 +167,7 @@ export const secretRotationV2QueueServiceFactory = async ({
|
|||||||
environment: environment.name,
|
environment: environment.name,
|
||||||
projectName: project.name,
|
projectName: project.name,
|
||||||
rotationUrl: encodeURI(
|
rotationUrl: encodeURI(
|
||||||
`${appCfg.SITE_URL}/projects/${projectId}/secret-manager/secrets/${environment.slug}`
|
`${appCfg.SITE_URL}/projects/secret-management/${projectId}/secrets/${environment.slug}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -2,8 +2,9 @@ import { ForbiddenError, subject } from "@casl/ability";
|
|||||||
import { Knex } from "knex";
|
import { Knex } from "knex";
|
||||||
import isEqual from "lodash.isequal";
|
import isEqual from "lodash.isequal";
|
||||||
|
|
||||||
import { SecretType, TableName } from "@app/db/schemas";
|
import { ActionProjectType, SecretType, TableName } from "@app/db/schemas";
|
||||||
import { EventType, TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-types";
|
import { EventType, TAuditLogServiceFactory } from "@app/ee/services/audit-log/audit-log-types";
|
||||||
|
import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { hasSecretReadValueOrDescribePermission } from "@app/ee/services/permission/permission-fns";
|
import { hasSecretReadValueOrDescribePermission } from "@app/ee/services/permission/permission-fns";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
@@ -82,6 +83,7 @@ import { TSecretVersionV2DALFactory } from "@app/services/secret-v2-bridge/secre
|
|||||||
import { TSecretVersionV2TagDALFactory } from "@app/services/secret-v2-bridge/secret-version-tag-dal";
|
import { TSecretVersionV2TagDALFactory } from "@app/services/secret-v2-bridge/secret-version-tag-dal";
|
||||||
|
|
||||||
import { awsIamUserSecretRotationFactory } from "./aws-iam-user-secret/aws-iam-user-secret-rotation-fns";
|
import { awsIamUserSecretRotationFactory } from "./aws-iam-user-secret/aws-iam-user-secret-rotation-fns";
|
||||||
|
import { oktaClientSecretRotationFactory } from "./okta-client-secret/okta-client-secret-rotation-fns";
|
||||||
import { TSecretRotationV2DALFactory } from "./secret-rotation-v2-dal";
|
import { TSecretRotationV2DALFactory } from "./secret-rotation-v2-dal";
|
||||||
|
|
||||||
export type TSecretRotationV2ServiceFactoryDep = {
|
export type TSecretRotationV2ServiceFactoryDep = {
|
||||||
@@ -107,6 +109,7 @@ export type TSecretRotationV2ServiceFactoryDep = {
|
|||||||
queueService: Pick<TQueueServiceFactory, "queuePg">;
|
queueService: Pick<TQueueServiceFactory, "queuePg">;
|
||||||
appConnectionDAL: Pick<TAppConnectionDALFactory, "findById" | "update" | "updateById">;
|
appConnectionDAL: Pick<TAppConnectionDALFactory, "findById" | "update" | "updateById">;
|
||||||
folderCommitService: Pick<TFolderCommitServiceFactory, "createCommit">;
|
folderCommitService: Pick<TFolderCommitServiceFactory, "createCommit">;
|
||||||
|
gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TSecretRotationV2ServiceFactory = ReturnType<typeof secretRotationV2ServiceFactory>;
|
export type TSecretRotationV2ServiceFactory = ReturnType<typeof secretRotationV2ServiceFactory>;
|
||||||
@@ -126,7 +129,8 @@ const SECRET_ROTATION_FACTORY_MAP: Record<SecretRotation, TRotationFactoryImplem
|
|||||||
[SecretRotation.Auth0ClientSecret]: auth0ClientSecretRotationFactory as TRotationFactoryImplementation,
|
[SecretRotation.Auth0ClientSecret]: auth0ClientSecretRotationFactory as TRotationFactoryImplementation,
|
||||||
[SecretRotation.AzureClientSecret]: azureClientSecretRotationFactory as TRotationFactoryImplementation,
|
[SecretRotation.AzureClientSecret]: azureClientSecretRotationFactory as TRotationFactoryImplementation,
|
||||||
[SecretRotation.AwsIamUserSecret]: awsIamUserSecretRotationFactory as TRotationFactoryImplementation,
|
[SecretRotation.AwsIamUserSecret]: awsIamUserSecretRotationFactory as TRotationFactoryImplementation,
|
||||||
[SecretRotation.LdapPassword]: ldapPasswordRotationFactory as TRotationFactoryImplementation
|
[SecretRotation.LdapPassword]: ldapPasswordRotationFactory as TRotationFactoryImplementation,
|
||||||
|
[SecretRotation.OktaClientSecret]: oktaClientSecretRotationFactory as TRotationFactoryImplementation
|
||||||
};
|
};
|
||||||
|
|
||||||
export const secretRotationV2ServiceFactory = ({
|
export const secretRotationV2ServiceFactory = ({
|
||||||
@@ -148,7 +152,8 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
keyStore,
|
keyStore,
|
||||||
queueService,
|
queueService,
|
||||||
folderCommitService,
|
folderCommitService,
|
||||||
appConnectionDAL
|
appConnectionDAL,
|
||||||
|
gatewayService
|
||||||
}: TSecretRotationV2ServiceFactoryDep) => {
|
}: TSecretRotationV2ServiceFactoryDep) => {
|
||||||
const $queueSendSecretRotationStatusNotification = async (secretRotation: TSecretRotationV2Raw) => {
|
const $queueSendSecretRotationStatusNotification = async (secretRotation: TSecretRotationV2Raw) => {
|
||||||
const appCfg = getConfig();
|
const appCfg = getConfig();
|
||||||
@@ -218,7 +223,7 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -269,7 +274,7 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -315,7 +320,7 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -380,7 +385,7 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -424,7 +429,7 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -461,7 +466,8 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
rotationInterval: payload.rotationInterval
|
rotationInterval: payload.rotationInterval
|
||||||
} as TSecretRotationV2WithConnection,
|
} as TSecretRotationV2WithConnection,
|
||||||
appConnectionDAL,
|
appConnectionDAL,
|
||||||
kmsService
|
kmsService,
|
||||||
|
gatewayService
|
||||||
);
|
);
|
||||||
|
|
||||||
// even though we have a db constraint we want to check before any rotation of credentials is attempted
|
// even though we have a db constraint we want to check before any rotation of credentials is attempted
|
||||||
@@ -625,7 +631,7 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -775,7 +781,7 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -824,7 +830,8 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
connection: appConnection
|
connection: appConnection
|
||||||
} as TSecretRotationV2WithConnection,
|
} as TSecretRotationV2WithConnection,
|
||||||
appConnectionDAL,
|
appConnectionDAL,
|
||||||
kmsService
|
kmsService,
|
||||||
|
gatewayService
|
||||||
);
|
);
|
||||||
|
|
||||||
const generatedCredentials = await decryptSecretRotationCredentials({
|
const generatedCredentials = await decryptSecretRotationCredentials({
|
||||||
@@ -907,7 +914,8 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
connection: appConnection
|
connection: appConnection
|
||||||
} as TSecretRotationV2WithConnection,
|
} as TSecretRotationV2WithConnection,
|
||||||
appConnectionDAL,
|
appConnectionDAL,
|
||||||
kmsService
|
kmsService,
|
||||||
|
gatewayService
|
||||||
);
|
);
|
||||||
|
|
||||||
const updatedRotation = await rotationFactory.rotateCredentials(
|
const updatedRotation = await rotationFactory.rotateCredentials(
|
||||||
@@ -1105,7 +1113,7 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1152,7 +1160,7 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1204,7 +1212,7 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1320,7 +1328,8 @@ export const secretRotationV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
const permissiveFolderMappings = folderMappings.filter(({ path, environment }) =>
|
const permissiveFolderMappings = folderMappings.filter(({ path, environment }) =>
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { AuditLogInfo } from "@app/ee/services/audit-log/audit-log-types";
|
import { AuditLogInfo } from "@app/ee/services/audit-log/audit-log-types";
|
||||||
|
import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service";
|
||||||
import { TSqlCredentialsRotationGeneratedCredentials } from "@app/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-types";
|
import { TSqlCredentialsRotationGeneratedCredentials } from "@app/ee/services/secret-rotation-v2/shared/sql-credentials/sql-credentials-rotation-types";
|
||||||
import { OrderByDirection } from "@app/lib/types";
|
import { OrderByDirection } from "@app/lib/types";
|
||||||
import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
|
import { TAppConnectionDALFactory } from "@app/services/app-connection/app-connection-dal";
|
||||||
@@ -45,6 +46,13 @@ import {
|
|||||||
TMySqlCredentialsRotationListItem,
|
TMySqlCredentialsRotationListItem,
|
||||||
TMySqlCredentialsRotationWithConnection
|
TMySqlCredentialsRotationWithConnection
|
||||||
} from "./mysql-credentials";
|
} from "./mysql-credentials";
|
||||||
|
import {
|
||||||
|
TOktaClientSecretRotation,
|
||||||
|
TOktaClientSecretRotationGeneratedCredentials,
|
||||||
|
TOktaClientSecretRotationInput,
|
||||||
|
TOktaClientSecretRotationListItem,
|
||||||
|
TOktaClientSecretRotationWithConnection
|
||||||
|
} from "./okta-client-secret";
|
||||||
import {
|
import {
|
||||||
TOracleDBCredentialsRotation,
|
TOracleDBCredentialsRotation,
|
||||||
TOracleDBCredentialsRotationInput,
|
TOracleDBCredentialsRotationInput,
|
||||||
@@ -68,7 +76,8 @@ export type TSecretRotationV2 =
|
|||||||
| TAuth0ClientSecretRotation
|
| TAuth0ClientSecretRotation
|
||||||
| TAzureClientSecretRotation
|
| TAzureClientSecretRotation
|
||||||
| TLdapPasswordRotation
|
| TLdapPasswordRotation
|
||||||
| TAwsIamUserSecretRotation;
|
| TAwsIamUserSecretRotation
|
||||||
|
| TOktaClientSecretRotation;
|
||||||
|
|
||||||
export type TSecretRotationV2WithConnection =
|
export type TSecretRotationV2WithConnection =
|
||||||
| TPostgresCredentialsRotationWithConnection
|
| TPostgresCredentialsRotationWithConnection
|
||||||
@@ -78,14 +87,16 @@ export type TSecretRotationV2WithConnection =
|
|||||||
| TAuth0ClientSecretRotationWithConnection
|
| TAuth0ClientSecretRotationWithConnection
|
||||||
| TAzureClientSecretRotationWithConnection
|
| TAzureClientSecretRotationWithConnection
|
||||||
| TLdapPasswordRotationWithConnection
|
| TLdapPasswordRotationWithConnection
|
||||||
| TAwsIamUserSecretRotationWithConnection;
|
| TAwsIamUserSecretRotationWithConnection
|
||||||
|
| TOktaClientSecretRotationWithConnection;
|
||||||
|
|
||||||
export type TSecretRotationV2GeneratedCredentials =
|
export type TSecretRotationV2GeneratedCredentials =
|
||||||
| TSqlCredentialsRotationGeneratedCredentials
|
| TSqlCredentialsRotationGeneratedCredentials
|
||||||
| TAuth0ClientSecretRotationGeneratedCredentials
|
| TAuth0ClientSecretRotationGeneratedCredentials
|
||||||
| TAzureClientSecretRotationGeneratedCredentials
|
| TAzureClientSecretRotationGeneratedCredentials
|
||||||
| TLdapPasswordRotationGeneratedCredentials
|
| TLdapPasswordRotationGeneratedCredentials
|
||||||
| TAwsIamUserSecretRotationGeneratedCredentials;
|
| TAwsIamUserSecretRotationGeneratedCredentials
|
||||||
|
| TOktaClientSecretRotationGeneratedCredentials;
|
||||||
|
|
||||||
export type TSecretRotationV2Input =
|
export type TSecretRotationV2Input =
|
||||||
| TPostgresCredentialsRotationInput
|
| TPostgresCredentialsRotationInput
|
||||||
@@ -95,7 +106,8 @@ export type TSecretRotationV2Input =
|
|||||||
| TAuth0ClientSecretRotationInput
|
| TAuth0ClientSecretRotationInput
|
||||||
| TAzureClientSecretRotationInput
|
| TAzureClientSecretRotationInput
|
||||||
| TLdapPasswordRotationInput
|
| TLdapPasswordRotationInput
|
||||||
| TAwsIamUserSecretRotationInput;
|
| TAwsIamUserSecretRotationInput
|
||||||
|
| TOktaClientSecretRotationInput;
|
||||||
|
|
||||||
export type TSecretRotationV2ListItem =
|
export type TSecretRotationV2ListItem =
|
||||||
| TPostgresCredentialsRotationListItem
|
| TPostgresCredentialsRotationListItem
|
||||||
@@ -105,7 +117,8 @@ export type TSecretRotationV2ListItem =
|
|||||||
| TAuth0ClientSecretRotationListItem
|
| TAuth0ClientSecretRotationListItem
|
||||||
| TAzureClientSecretRotationListItem
|
| TAzureClientSecretRotationListItem
|
||||||
| TLdapPasswordRotationListItem
|
| TLdapPasswordRotationListItem
|
||||||
| TAwsIamUserSecretRotationListItem;
|
| TAwsIamUserSecretRotationListItem
|
||||||
|
| TOktaClientSecretRotationListItem;
|
||||||
|
|
||||||
export type TSecretRotationV2TemporaryParameters = TLdapPasswordRotationInput["temporaryParameters"] | undefined;
|
export type TSecretRotationV2TemporaryParameters = TLdapPasswordRotationInput["temporaryParameters"] | undefined;
|
||||||
|
|
||||||
@@ -239,7 +252,8 @@ export type TRotationFactory<
|
|||||||
> = (
|
> = (
|
||||||
secretRotation: T,
|
secretRotation: T,
|
||||||
appConnectionDAL: Pick<TAppConnectionDALFactory, "findById" | "update" | "updateById">,
|
appConnectionDAL: Pick<TAppConnectionDALFactory, "findById" | "update" | "updateById">,
|
||||||
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">
|
kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">,
|
||||||
|
gatewayService: Pick<TGatewayServiceFactory, "fnGetGatewayClientTlsByGatewayId">
|
||||||
) => {
|
) => {
|
||||||
issueCredentials: TRotationFactoryIssueCredentials<C, P>;
|
issueCredentials: TRotationFactoryIssueCredentials<C, P>;
|
||||||
revokeCredentials: TRotationFactoryRevokeCredentials<C>;
|
revokeCredentials: TRotationFactoryRevokeCredentials<C>;
|
||||||
|
@@ -6,6 +6,7 @@ import { AzureClientSecretRotationSchema } from "@app/ee/services/secret-rotatio
|
|||||||
import { LdapPasswordRotationSchema } from "@app/ee/services/secret-rotation-v2/ldap-password";
|
import { LdapPasswordRotationSchema } from "@app/ee/services/secret-rotation-v2/ldap-password";
|
||||||
import { MsSqlCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/mssql-credentials";
|
import { MsSqlCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/mssql-credentials";
|
||||||
import { MySqlCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/mysql-credentials";
|
import { MySqlCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/mysql-credentials";
|
||||||
|
import { OktaClientSecretRotationSchema } from "@app/ee/services/secret-rotation-v2/okta-client-secret";
|
||||||
import { OracleDBCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/oracledb-credentials";
|
import { OracleDBCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/oracledb-credentials";
|
||||||
import { PostgresCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/postgres-credentials";
|
import { PostgresCredentialsRotationSchema } from "@app/ee/services/secret-rotation-v2/postgres-credentials";
|
||||||
|
|
||||||
@@ -17,5 +18,6 @@ export const SecretRotationV2Schema = z.discriminatedUnion("type", [
|
|||||||
Auth0ClientSecretRotationSchema,
|
Auth0ClientSecretRotationSchema,
|
||||||
AzureClientSecretRotationSchema,
|
AzureClientSecretRotationSchema,
|
||||||
LdapPasswordRotationSchema,
|
LdapPasswordRotationSchema,
|
||||||
AwsIamUserSecretRotationSchema
|
AwsIamUserSecretRotationSchema,
|
||||||
|
OktaClientSecretRotationSchema
|
||||||
]);
|
]);
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
TRotationFactory,
|
TRotationFactory,
|
||||||
TRotationFactoryGetSecretsPayload,
|
TRotationFactoryGetSecretsPayload,
|
||||||
@@ -5,9 +7,13 @@ import {
|
|||||||
TRotationFactoryRevokeCredentials,
|
TRotationFactoryRevokeCredentials,
|
||||||
TRotationFactoryRotateCredentials
|
TRotationFactoryRotateCredentials
|
||||||
} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";
|
} from "@app/ee/services/secret-rotation-v2/secret-rotation-v2-types";
|
||||||
import { getSqlConnectionClient, SQL_CONNECTION_ALTER_LOGIN_STATEMENT } from "@app/services/app-connection/shared/sql";
|
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||||
|
import {
|
||||||
|
executeWithPotentialGateway,
|
||||||
|
SQL_CONNECTION_ALTER_LOGIN_STATEMENT
|
||||||
|
} from "@app/services/app-connection/shared/sql";
|
||||||
|
|
||||||
import { generatePassword } from "../utils";
|
import { DEFAULT_PASSWORD_REQUIREMENTS, generatePassword } from "../utils";
|
||||||
import {
|
import {
|
||||||
TSqlCredentialsRotationGeneratedCredentials,
|
TSqlCredentialsRotationGeneratedCredentials,
|
||||||
TSqlCredentialsRotationWithConnection
|
TSqlCredentialsRotationWithConnection
|
||||||
@@ -27,10 +33,15 @@ const redactPasswords = (e: unknown, credentials: TSqlCredentialsRotationGenerat
|
|||||||
return redactedMessage;
|
return redactedMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ORACLE_PASSWORD_REQUIREMENTS = {
|
||||||
|
...DEFAULT_PASSWORD_REQUIREMENTS,
|
||||||
|
length: 30
|
||||||
|
};
|
||||||
|
|
||||||
export const sqlCredentialsRotationFactory: TRotationFactory<
|
export const sqlCredentialsRotationFactory: TRotationFactory<
|
||||||
TSqlCredentialsRotationWithConnection,
|
TSqlCredentialsRotationWithConnection,
|
||||||
TSqlCredentialsRotationGeneratedCredentials
|
TSqlCredentialsRotationGeneratedCredentials
|
||||||
> = (secretRotation) => {
|
> = (secretRotation, _appConnectionDAL, _kmsService, gatewayService) => {
|
||||||
const {
|
const {
|
||||||
connection,
|
connection,
|
||||||
parameters: { username1, username2 },
|
parameters: { username1, username2 },
|
||||||
@@ -38,46 +49,60 @@ export const sqlCredentialsRotationFactory: TRotationFactory<
|
|||||||
secretsMapping
|
secretsMapping
|
||||||
} = secretRotation;
|
} = secretRotation;
|
||||||
|
|
||||||
const $validateCredentials = async (credentials: TSqlCredentialsRotationGeneratedCredentials[number]) => {
|
const passwordRequirement =
|
||||||
const client = await getSqlConnectionClient({
|
connection.app === AppConnection.OracleDB ? ORACLE_PASSWORD_REQUIREMENTS : DEFAULT_PASSWORD_REQUIREMENTS;
|
||||||
...connection,
|
|
||||||
credentials: {
|
|
||||||
...connection.credentials,
|
|
||||||
...credentials
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
const executeOperation = <T>(
|
||||||
|
operation: (client: Knex) => Promise<T>,
|
||||||
|
credentialsOverride?: TSqlCredentialsRotationGeneratedCredentials[number]
|
||||||
|
) => {
|
||||||
|
const finalCredentials = {
|
||||||
|
...connection.credentials,
|
||||||
|
...credentialsOverride
|
||||||
|
};
|
||||||
|
|
||||||
|
return executeWithPotentialGateway(
|
||||||
|
{
|
||||||
|
...connection,
|
||||||
|
credentials: finalCredentials
|
||||||
|
},
|
||||||
|
gatewayService,
|
||||||
|
(client) => operation(client)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const $validateCredentials = async (credentials: TSqlCredentialsRotationGeneratedCredentials[number]) => {
|
||||||
try {
|
try {
|
||||||
await client.raw("SELECT 1");
|
await executeOperation(async (client) => {
|
||||||
|
await client.raw(connection.app === AppConnection.OracleDB ? `SELECT 1 FROM DUAL` : `Select 1`);
|
||||||
|
}, credentials);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(redactPasswords(error, [credentials]));
|
throw new Error(redactPasswords(error, [credentials]));
|
||||||
} finally {
|
|
||||||
await client.destroy();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const issueCredentials: TRotationFactoryIssueCredentials<TSqlCredentialsRotationGeneratedCredentials> = async (
|
const issueCredentials: TRotationFactoryIssueCredentials<TSqlCredentialsRotationGeneratedCredentials> = async (
|
||||||
callback
|
callback
|
||||||
) => {
|
) => {
|
||||||
const client = await getSqlConnectionClient(connection);
|
// For SQL, since we get existing users, we change both their passwords
|
||||||
|
// on issue to invalidate their existing passwords
|
||||||
// For SQL, since we get existing users, we change both their passwords
|
// For SQL, since we get existing users, we change both their passwords
|
||||||
// on issue to invalidate their existing passwords
|
// on issue to invalidate their existing passwords
|
||||||
const credentialsSet = [
|
const credentialsSet = [
|
||||||
{ username: username1, password: generatePassword() },
|
{ username: username1, password: generatePassword(passwordRequirement) },
|
||||||
{ username: username2, password: generatePassword() }
|
{ username: username2, password: generatePassword(passwordRequirement) }
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.transaction(async (tx) => {
|
await executeOperation(async (client) => {
|
||||||
for await (const credentials of credentialsSet) {
|
await client.transaction(async (tx) => {
|
||||||
await tx.raw(...SQL_CONNECTION_ALTER_LOGIN_STATEMENT[connection.app](credentials));
|
for await (const credentials of credentialsSet) {
|
||||||
}
|
await tx.raw(...SQL_CONNECTION_ALTER_LOGIN_STATEMENT[connection.app](credentials));
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(redactPasswords(error, credentialsSet));
|
throw new Error(redactPasswords(error, credentialsSet));
|
||||||
} finally {
|
|
||||||
await client.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for await (const credentials of credentialsSet) {
|
for await (const credentials of credentialsSet) {
|
||||||
@@ -91,21 +116,22 @@ export const sqlCredentialsRotationFactory: TRotationFactory<
|
|||||||
credentialsToRevoke,
|
credentialsToRevoke,
|
||||||
callback
|
callback
|
||||||
) => {
|
) => {
|
||||||
const client = await getSqlConnectionClient(connection);
|
const revokedCredentials = credentialsToRevoke.map(({ username }) => ({
|
||||||
|
username,
|
||||||
const revokedCredentials = credentialsToRevoke.map(({ username }) => ({ username, password: generatePassword() }));
|
password: generatePassword(passwordRequirement)
|
||||||
|
}));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.transaction(async (tx) => {
|
await executeOperation(async (client) => {
|
||||||
for await (const credentials of revokedCredentials) {
|
await client.transaction(async (tx) => {
|
||||||
// invalidate previous passwords
|
for await (const credentials of revokedCredentials) {
|
||||||
await tx.raw(...SQL_CONNECTION_ALTER_LOGIN_STATEMENT[connection.app](credentials));
|
// invalidate previous passwords
|
||||||
}
|
await tx.raw(...SQL_CONNECTION_ALTER_LOGIN_STATEMENT[connection.app](credentials));
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(redactPasswords(error, revokedCredentials));
|
throw new Error(redactPasswords(error, revokedCredentials));
|
||||||
} finally {
|
|
||||||
await client.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return callback();
|
return callback();
|
||||||
@@ -115,17 +141,18 @@ export const sqlCredentialsRotationFactory: TRotationFactory<
|
|||||||
_,
|
_,
|
||||||
callback
|
callback
|
||||||
) => {
|
) => {
|
||||||
const client = await getSqlConnectionClient(connection);
|
|
||||||
|
|
||||||
// generate new password for the next active user
|
// generate new password for the next active user
|
||||||
const credentials = { username: activeIndex === 0 ? username2 : username1, password: generatePassword() };
|
const credentials = {
|
||||||
|
username: activeIndex === 0 ? username2 : username1,
|
||||||
|
password: generatePassword(passwordRequirement)
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.raw(...SQL_CONNECTION_ALTER_LOGIN_STATEMENT[connection.app](credentials));
|
await executeOperation(async (client) => {
|
||||||
|
await client.raw(...SQL_CONNECTION_ALTER_LOGIN_STATEMENT[connection.app](credentials));
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(redactPasswords(error, [credentials]));
|
throw new Error(redactPasswords(error, [credentials]));
|
||||||
} finally {
|
|
||||||
await client.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await $validateCredentials(credentials);
|
await $validateCredentials(credentials);
|
||||||
|
@@ -11,7 +11,7 @@ type TPasswordRequirements = {
|
|||||||
allowedSymbols?: string;
|
allowedSymbols?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_PASSWORD_REQUIREMENTS: TPasswordRequirements = {
|
export const DEFAULT_PASSWORD_REQUIREMENTS: TPasswordRequirements = {
|
||||||
length: 48,
|
length: 48,
|
||||||
required: {
|
required: {
|
||||||
lowercase: 1,
|
lowercase: 1,
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { ForbiddenError, subject } from "@casl/ability";
|
import { ForbiddenError, subject } from "@casl/ability";
|
||||||
import Ajv from "ajv";
|
import Ajv from "ajv";
|
||||||
|
|
||||||
import { ProjectVersion, TableName } from "@app/db/schemas";
|
import { ActionProjectType, ProjectVersion, TableName } from "@app/db/schemas";
|
||||||
import { crypto, SymmetricKeySize } from "@app/lib/crypto/cryptography";
|
import { crypto, SymmetricKeySize } from "@app/lib/crypto/cryptography";
|
||||||
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
import { TProjectPermission } from "@app/lib/types";
|
import { TProjectPermission } from "@app/lib/types";
|
||||||
@@ -66,7 +66,8 @@ export const secretRotationServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionSecretRotationActions.Read,
|
ProjectPermissionSecretRotationActions.Read,
|
||||||
@@ -97,7 +98,8 @@ export const secretRotationServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionSecretRotationActions.Read,
|
ProjectPermissionSecretRotationActions.Read,
|
||||||
@@ -213,7 +215,8 @@ export const secretRotationServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionSecretRotationActions.Read,
|
ProjectPermissionSecretRotationActions.Read,
|
||||||
@@ -263,7 +266,8 @@ export const secretRotationServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionSecretRotationActions.Edit,
|
ProjectPermissionSecretRotationActions.Edit,
|
||||||
@@ -283,7 +287,8 @@ export const secretRotationServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: doc.projectId,
|
projectId: doc.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionSecretRotationActions.Delete,
|
ProjectPermissionSecretRotationActions.Delete,
|
||||||
|
@@ -1,11 +1,21 @@
|
|||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
import { exec } from "child_process";
|
import { exec } from "child_process";
|
||||||
|
import { join } from "path";
|
||||||
|
import picomatch from "picomatch";
|
||||||
import RE2 from "re2";
|
import RE2 from "re2";
|
||||||
|
|
||||||
import { readFindingsFile } from "@app/ee/services/secret-scanning/secret-scanning-queue/secret-scanning-fns";
|
import {
|
||||||
|
createTempFolder,
|
||||||
|
deleteTempFolder,
|
||||||
|
readFindingsFile,
|
||||||
|
writeTextToFile
|
||||||
|
} from "@app/ee/services/secret-scanning/secret-scanning-queue/secret-scanning-fns";
|
||||||
import { SecretMatch } from "@app/ee/services/secret-scanning/secret-scanning-queue/secret-scanning-queue-types";
|
import { SecretMatch } from "@app/ee/services/secret-scanning/secret-scanning-queue/secret-scanning-queue-types";
|
||||||
import { BITBUCKET_SECRET_SCANNING_DATA_SOURCE_LIST_OPTION } from "@app/ee/services/secret-scanning-v2/bitbucket";
|
import { BITBUCKET_SECRET_SCANNING_DATA_SOURCE_LIST_OPTION } from "@app/ee/services/secret-scanning-v2/bitbucket";
|
||||||
import { GITHUB_SECRET_SCANNING_DATA_SOURCE_LIST_OPTION } from "@app/ee/services/secret-scanning-v2/github";
|
import { GITHUB_SECRET_SCANNING_DATA_SOURCE_LIST_OPTION } from "@app/ee/services/secret-scanning-v2/github";
|
||||||
|
import { getConfig } from "@app/lib/config/env";
|
||||||
|
import { crypto } from "@app/lib/crypto";
|
||||||
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
import { titleCaseToCamelCase } from "@app/lib/fn";
|
import { titleCaseToCamelCase } from "@app/lib/fn";
|
||||||
|
|
||||||
import { SecretScanningDataSource, SecretScanningFindingSeverity } from "./secret-scanning-v2-enums";
|
import { SecretScanningDataSource, SecretScanningFindingSeverity } from "./secret-scanning-v2-enums";
|
||||||
@@ -46,6 +56,19 @@ export function scanDirectory(inputPath: string, outputPath: string, configPath?
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function scanFile(inputPath: string): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const command = `infisical scan --exit-code=77 --source "${inputPath}" --no-git`;
|
||||||
|
exec(command, (error) => {
|
||||||
|
if (error && error.code === 77) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export const scanGitRepositoryAndGetFindings = async (
|
export const scanGitRepositoryAndGetFindings = async (
|
||||||
scanPath: string,
|
scanPath: string,
|
||||||
findingsPath: string,
|
findingsPath: string,
|
||||||
@@ -140,3 +163,47 @@ export const parseScanErrorMessage = (err: unknown): string => {
|
|||||||
? errorMessage
|
? errorMessage
|
||||||
: `${errorMessage.substring(0, MAX_MESSAGE_LENGTH - 3)}...`;
|
: `${errorMessage.substring(0, MAX_MESSAGE_LENGTH - 3)}...`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const scanSecretPolicyViolations = async (
|
||||||
|
projectId: string,
|
||||||
|
secretPath: string,
|
||||||
|
secrets: { secretKey: string; secretValue: string }[],
|
||||||
|
ignoreValues: string[]
|
||||||
|
) => {
|
||||||
|
const appCfg = getConfig();
|
||||||
|
|
||||||
|
if (!appCfg.PARAMS_FOLDER_SECRET_DETECTION_ENABLED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const match = appCfg.PARAMS_FOLDER_SECRET_DETECTION_PATHS?.find(
|
||||||
|
(el) => el.projectId === projectId && picomatch.isMatch(secretPath, el.secretPath, { strictSlashes: false })
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!match) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tempFolder = await createTempFolder();
|
||||||
|
try {
|
||||||
|
const scanPromises = secrets
|
||||||
|
.filter((secret) => !ignoreValues.includes(secret.secretValue))
|
||||||
|
.map(async (secret) => {
|
||||||
|
const secretFilePath = join(tempFolder, `${crypto.nativeCrypto.randomUUID()}.txt`);
|
||||||
|
await writeTextToFile(secretFilePath, `${secret.secretKey}=${secret.secretValue}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await scanFile(secretFilePath);
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `Secret value detected in ${secret.secretKey}. Please add this instead to the designated secrets path in the project.`,
|
||||||
|
name: "SecretPolicyViolation"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(scanPromises);
|
||||||
|
} finally {
|
||||||
|
await deleteTempFolder(tempFolder);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@@ -567,14 +567,18 @@ export const secretScanningV2QueueServiceFactory = async ({
|
|||||||
const projectMembers = await projectMembershipDAL.findAllProjectMembers(projectId);
|
const projectMembers = await projectMembershipDAL.findAllProjectMembers(projectId);
|
||||||
const project = await projectDAL.findById(projectId);
|
const project = await projectDAL.findById(projectId);
|
||||||
|
|
||||||
const projectAdmins = projectMembers.filter((member) =>
|
const recipients = projectMembers.filter((member) => {
|
||||||
member.roles.some((role) => role.role === ProjectMembershipRole.Admin)
|
const isAdmin = member.roles.some((role) => role.role === ProjectMembershipRole.Admin);
|
||||||
);
|
const isCompleted = payload.status === SecretScanningScanStatus.Completed;
|
||||||
|
// We assume that the committer is one of the project members
|
||||||
|
const isCommitter = isCompleted && payload.authorEmail === member.user.email;
|
||||||
|
return isAdmin || isCommitter;
|
||||||
|
});
|
||||||
|
|
||||||
const timestamp = new Date().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
|
|
||||||
await smtpService.sendMail({
|
await smtpService.sendMail({
|
||||||
recipients: projectAdmins.map((member) => member.user.email!).filter(Boolean),
|
recipients: recipients.map((member) => member.user.email!).filter(Boolean),
|
||||||
template:
|
template:
|
||||||
payload.status === SecretScanningScanStatus.Completed
|
payload.status === SecretScanningScanStatus.Completed
|
||||||
? SmtpTemplates.SecretScanningV2SecretsDetected
|
? SmtpTemplates.SecretScanningV2SecretsDetected
|
||||||
@@ -592,7 +596,7 @@ export const secretScanningV2QueueServiceFactory = async ({
|
|||||||
numberOfSecrets: payload.numberOfSecrets,
|
numberOfSecrets: payload.numberOfSecrets,
|
||||||
isDiffScan: payload.isDiffScan,
|
isDiffScan: payload.isDiffScan,
|
||||||
url: encodeURI(
|
url: encodeURI(
|
||||||
`${appCfg.SITE_URL}/projects/${projectId}/secret-scanning/findings?search=scanId:${payload.scanId}`
|
`${appCfg.SITE_URL}/projects/secret-scanning/${projectId}/findings?search=scanId:${payload.scanId}`
|
||||||
),
|
),
|
||||||
timestamp
|
timestamp
|
||||||
}
|
}
|
||||||
@@ -603,7 +607,7 @@ export const secretScanningV2QueueServiceFactory = async ({
|
|||||||
timestamp,
|
timestamp,
|
||||||
errorMessage: payload.errorMessage,
|
errorMessage: payload.errorMessage,
|
||||||
url: encodeURI(
|
url: encodeURI(
|
||||||
`${appCfg.SITE_URL}/projects/${projectId}/secret-scanning/data-sources/${dataSource.type}/${dataSource.id}`
|
`${appCfg.SITE_URL}/projects/secret-scanning/${projectId}/data-sources/${dataSource.type}/${dataSource.id}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
import {
|
import {
|
||||||
@@ -94,7 +95,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -156,7 +157,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId: dataSource.projectId
|
projectId: dataSource.projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -201,7 +202,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -235,7 +236,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId: payload.projectId
|
projectId: payload.projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -348,7 +349,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId: dataSource.projectId
|
projectId: dataSource.projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -401,6 +402,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId: dataSource.projectId
|
projectId: dataSource.projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -474,7 +476,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId: dataSource.projectId
|
projectId: dataSource.projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -538,7 +540,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId: dataSource.projectId
|
projectId: dataSource.projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -583,7 +585,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId: dataSource.projectId
|
projectId: dataSource.projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -626,7 +628,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId: dataSource.projectId
|
projectId: dataSource.projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -669,7 +671,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId: dataSource.projectId
|
projectId: dataSource.projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -702,7 +704,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -736,7 +738,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -776,7 +778,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId: finding.projectId
|
projectId: finding.projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -807,7 +809,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -842,7 +844,7 @@ export const secretScanningV2ServiceFactory = ({
|
|||||||
actorId: actor.id,
|
actorId: actor.id,
|
||||||
actorAuthMethod: actor.authMethod,
|
actorAuthMethod: actor.authMethod,
|
||||||
actorOrgId: actor.orgId,
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretScanning,
|
||||||
projectId
|
projectId
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
// akhilmhdh: I did this, quite strange bug with eslint. Everything do have a type stil has this error
|
// akhilmhdh: I did this, quite strange bug with eslint. Everything do have a type stil has this error
|
||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
|
|
||||||
import { TableName, TSecretTagJunctionInsert, TSecretV2TagJunctionInsert } from "@app/db/schemas";
|
import { ActionProjectType, TableName, TSecretTagJunctionInsert, TSecretV2TagJunctionInsert } from "@app/db/schemas";
|
||||||
import { crypto, SymmetricKeySize } from "@app/lib/crypto/cryptography";
|
import { crypto, SymmetricKeySize } from "@app/lib/crypto/cryptography";
|
||||||
import { InternalServerError, NotFoundError } from "@app/lib/errors";
|
import { InternalServerError, NotFoundError } from "@app/lib/errors";
|
||||||
import { groupBy } from "@app/lib/fn";
|
import { groupBy } from "@app/lib/fn";
|
||||||
@@ -103,7 +103,8 @@ export const secretSnapshotServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretRollback);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretRollback);
|
||||||
|
|
||||||
@@ -139,7 +140,8 @@ export const secretSnapshotServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretRollback);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretRollback);
|
||||||
|
|
||||||
@@ -167,7 +169,8 @@ export const secretSnapshotServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: snapshot.projectId,
|
projectId: snapshot.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretRollback);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SecretRollback);
|
||||||
@@ -391,7 +394,8 @@ export const secretSnapshotServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: snapshot.projectId,
|
projectId: snapshot.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SecretManager
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
ProjectPermissionActions.Create,
|
ProjectPermissionActions.Create,
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||||
@@ -58,7 +59,8 @@ export const sshCertificateTemplateServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: ca.projectId,
|
projectId: ca.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -130,7 +132,8 @@ export const sshCertificateTemplateServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: certTemplate.projectId,
|
projectId: certTemplate.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -198,7 +201,8 @@ export const sshCertificateTemplateServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: certificateTemplate.projectId,
|
projectId: certificateTemplate.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -224,7 +228,8 @@ export const sshCertificateTemplateServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: certTemplate.projectId,
|
projectId: certTemplate.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
import { TSshHostDALFactory } from "@app/ee/services/ssh-host/ssh-host-dal";
|
import { TSshHostDALFactory } from "@app/ee/services/ssh-host/ssh-host-dal";
|
||||||
@@ -79,7 +80,8 @@ export const sshHostGroupServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Create, ProjectPermissionSub.SshHostGroups);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Create, ProjectPermissionSub.SshHostGroups);
|
||||||
@@ -171,7 +173,8 @@ export const sshHostGroupServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: sshHostGroup.projectId,
|
projectId: sshHostGroup.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SshHostGroups);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SshHostGroups);
|
||||||
@@ -267,7 +270,8 @@ export const sshHostGroupServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: sshHostGroup.projectId,
|
projectId: sshHostGroup.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SshHostGroups);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SshHostGroups);
|
||||||
@@ -290,7 +294,8 @@ export const sshHostGroupServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: sshHostGroup.projectId,
|
projectId: sshHostGroup.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Delete, ProjectPermissionSub.SshHostGroups);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Delete, ProjectPermissionSub.SshHostGroups);
|
||||||
@@ -316,7 +321,8 @@ export const sshHostGroupServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: sshHostGroup.projectId,
|
projectId: sshHostGroup.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SshHostGroups);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.SshHostGroups);
|
||||||
@@ -354,7 +360,8 @@ export const sshHostGroupServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: sshHostGroup.projectId,
|
projectId: sshHostGroup.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SshHostGroups);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SshHostGroups);
|
||||||
@@ -393,7 +400,8 @@ export const sshHostGroupServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: sshHostGroup.projectId,
|
projectId: sshHostGroup.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SshHostGroups);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SshHostGroups);
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { Knex } from "knex";
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { BadRequestError } from "@app/lib/errors";
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
|
|
||||||
import { ProjectPermissionSshHostActions, ProjectPermissionSub } from "../permission/project-permission";
|
import { ProjectPermissionSshHostActions, ProjectPermissionSub } from "../permission/project-permission";
|
||||||
@@ -62,7 +63,8 @@ export const createSshLoginMappings = async ({
|
|||||||
userId: user.id,
|
userId: user.id,
|
||||||
projectId,
|
projectId,
|
||||||
authMethod: actorAuthMethod,
|
authMethod: actorAuthMethod,
|
||||||
userOrgId: actorOrgId
|
userOrgId: actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { ForbiddenError, subject } from "@casl/ability";
|
import { ForbiddenError, subject } from "@casl/ability";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
|
import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
import { ProjectPermissionSshHostActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionSshHostActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
@@ -111,7 +112,8 @@ export const sshHostServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
const projectHosts = await sshHostDAL.findUserAccessibleSshHosts([project.id], actorId);
|
const projectHosts = await sshHostDAL.findUserAccessibleSshHosts([project.id], actorId);
|
||||||
@@ -144,7 +146,8 @@ export const sshHostServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -273,7 +276,8 @@ export const sshHostServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: host.projectId,
|
projectId: host.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -334,7 +338,8 @@ export const sshHostServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: host.projectId,
|
projectId: host.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -362,7 +367,8 @@ export const sshHostServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: host.projectId,
|
projectId: host.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -401,7 +407,8 @@ export const sshHostServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: host.projectId,
|
projectId: host.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
const internalPrincipals = await convertActorToPrincipals({
|
const internalPrincipals = await convertActorToPrincipals({
|
||||||
@@ -520,7 +527,8 @@ export const sshHostServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: host.projectId,
|
projectId: host.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||||
import { TSshCertificateAuthorityDALFactory } from "@app/ee/services/ssh/ssh-certificate-authority-dal";
|
import { TSshCertificateAuthorityDALFactory } from "@app/ee/services/ssh/ssh-certificate-authority-dal";
|
||||||
@@ -72,7 +73,8 @@ export const sshCertificateAuthorityServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -107,7 +109,8 @@ export const sshCertificateAuthorityServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: ca.projectId,
|
projectId: ca.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -175,7 +178,8 @@ export const sshCertificateAuthorityServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: ca.projectId,
|
projectId: ca.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -213,7 +217,8 @@ export const sshCertificateAuthorityServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: ca.projectId,
|
projectId: ca.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -254,7 +259,8 @@ export const sshCertificateAuthorityServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: sshCertificateTemplate.projectId,
|
projectId: sshCertificateTemplate.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -375,7 +381,8 @@ export const sshCertificateAuthorityServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: sshCertificateTemplate.projectId,
|
projectId: sshCertificateTemplate.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
@@ -472,7 +479,8 @@ export const sshCertificateAuthorityServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId: ca.projectId,
|
projectId: ca.projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.SSH
|
||||||
});
|
});
|
||||||
|
|
||||||
ForbiddenError.from(permission).throwUnlessCan(
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
|
|
||||||
|
import { ActionProjectType } from "@app/db/schemas";
|
||||||
import { BadRequestError } from "@app/lib/errors";
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";
|
import { extractIPDetails, isValidIpOrCidr } from "@app/lib/ip";
|
||||||
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
||||||
@@ -35,7 +36,8 @@ export const trustedIpServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.IpAllowList);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.IpAllowList);
|
||||||
const trustedIps = await trustedIpDAL.find({
|
const trustedIps = await trustedIpDAL.find({
|
||||||
@@ -59,7 +61,8 @@ export const trustedIpServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Create, ProjectPermissionSub.IpAllowList);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Create, ProjectPermissionSub.IpAllowList);
|
||||||
|
|
||||||
@@ -104,7 +107,8 @@ export const trustedIpServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Create, ProjectPermissionSub.IpAllowList);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Create, ProjectPermissionSub.IpAllowList);
|
||||||
|
|
||||||
@@ -149,7 +153,8 @@ export const trustedIpServiceFactory = ({
|
|||||||
actorId,
|
actorId,
|
||||||
projectId,
|
projectId,
|
||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
});
|
});
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Create, ProjectPermissionSub.IpAllowList);
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Create, ProjectPermissionSub.IpAllowList);
|
||||||
|
|
||||||
|
@@ -704,7 +704,8 @@ export const PROJECTS = {
|
|||||||
hasDeleteProtection: "Enable or disable delete protection for the project.",
|
hasDeleteProtection: "Enable or disable delete protection for the project.",
|
||||||
secretSharing: "Enable or disable secret sharing for the project.",
|
secretSharing: "Enable or disable secret sharing for the project.",
|
||||||
showSnapshotsLegacy: "Enable or disable legacy snapshots for the project.",
|
showSnapshotsLegacy: "Enable or disable legacy snapshots for the project.",
|
||||||
defaultProduct: "The default product in which the project will open"
|
defaultProduct: "The default product in which the project will open",
|
||||||
|
secretDetectionIgnoreValues: "The list of secret values to ignore for secret detection."
|
||||||
},
|
},
|
||||||
GET_KEY: {
|
GET_KEY: {
|
||||||
workspaceId: "The ID of the project to get the key from."
|
workspaceId: "The ID of the project to get the key from."
|
||||||
@@ -2245,7 +2246,9 @@ export const AppConnections = {
|
|||||||
},
|
},
|
||||||
AZURE_CLIENT_SECRETS: {
|
AZURE_CLIENT_SECRETS: {
|
||||||
code: "The OAuth code to use to connect with Azure Client Secrets.",
|
code: "The OAuth code to use to connect with Azure Client Secrets.",
|
||||||
tenantId: "The Tenant ID to use to connect with Azure Client Secrets."
|
tenantId: "The Tenant ID to use to connect with Azure Client Secrets.",
|
||||||
|
clientId: "The Client ID to use to connect with Azure Client Secrets.",
|
||||||
|
clientSecret: "The Client Secret to use to connect with Azure Client Secrets."
|
||||||
},
|
},
|
||||||
AZURE_DEVOPS: {
|
AZURE_DEVOPS: {
|
||||||
code: "The OAuth code to use to connect with Azure DevOps.",
|
code: "The OAuth code to use to connect with Azure DevOps.",
|
||||||
@@ -2285,6 +2288,17 @@ export const AppConnections = {
|
|||||||
},
|
},
|
||||||
CHECKLY: {
|
CHECKLY: {
|
||||||
apiKey: "The API key used to authenticate with Checkly."
|
apiKey: "The API key used to authenticate with Checkly."
|
||||||
|
},
|
||||||
|
SUPABASE: {
|
||||||
|
accessKey: "The Key used to access Supabase.",
|
||||||
|
instanceUrl: "The URL used to access Supabase."
|
||||||
|
},
|
||||||
|
DIGITAL_OCEAN_APP_PLATFORM: {
|
||||||
|
apiToken: "The API token used to authenticate with Digital Ocean App Platform."
|
||||||
|
},
|
||||||
|
OKTA: {
|
||||||
|
instanceUrl: "The URL used to access your Okta organization.",
|
||||||
|
apiToken: "The API token used to authenticate with Okta."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2362,6 +2376,10 @@ export const SecretSyncs = {
|
|||||||
keyId: "The AWS KMS key ID or alias to use when encrypting parameters synced by Infisical.",
|
keyId: "The AWS KMS key ID or alias to use when encrypting parameters synced by Infisical.",
|
||||||
tags: "Optional tags to add to secrets synced by Infisical.",
|
tags: "Optional tags to add to secrets synced by Infisical.",
|
||||||
syncSecretMetadataAsTags: `Whether Infisical secret metadata should be added as tags to secrets synced by Infisical.`
|
syncSecretMetadataAsTags: `Whether Infisical secret metadata should be added as tags to secrets synced by Infisical.`
|
||||||
|
},
|
||||||
|
RENDER: {
|
||||||
|
autoRedeployServices:
|
||||||
|
"Whether Infisical should automatically redeploy the configured Render service upon secret changes."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DESTINATION_CONFIG: {
|
DESTINATION_CONFIG: {
|
||||||
@@ -2494,6 +2512,15 @@ export const SecretSyncs = {
|
|||||||
},
|
},
|
||||||
CHECKLY: {
|
CHECKLY: {
|
||||||
accountId: "The ID of the Checkly account to sync secrets to."
|
accountId: "The ID of the Checkly account to sync secrets to."
|
||||||
|
},
|
||||||
|
SUPABASE: {
|
||||||
|
projectId: "The ID of the Supabase project to sync secrets to.",
|
||||||
|
projectName: "The name of the Supabase project to sync secrets to."
|
||||||
|
},
|
||||||
|
BITBUCKET: {
|
||||||
|
workspaceSlug: "The Bitbucket Workspace slug to sync secrets to.",
|
||||||
|
repositorySlug: "The Bitbucket Repository slug to sync secrets to.",
|
||||||
|
environmentId: "The Bitbucket Deployment Environment uuid to sync secrets to."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2586,6 +2613,9 @@ export const SecretRotations = {
|
|||||||
AWS_IAM_USER_SECRET: {
|
AWS_IAM_USER_SECRET: {
|
||||||
userName: "The name of the client to rotate credentials for.",
|
userName: "The name of the client to rotate credentials for.",
|
||||||
region: "The AWS region the client is present in."
|
region: "The AWS region the client is present in."
|
||||||
|
},
|
||||||
|
OKTA_CLIENT_SECRET: {
|
||||||
|
clientId: "The ID of the Okta Application to rotate the client secret for."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SECRETS_MAPPING: {
|
SECRETS_MAPPING: {
|
||||||
@@ -2608,6 +2638,10 @@ export const SecretRotations = {
|
|||||||
AWS_IAM_USER_SECRET: {
|
AWS_IAM_USER_SECRET: {
|
||||||
accessKeyId: "The name of the secret that the access key ID will be mapped to.",
|
accessKeyId: "The name of the secret that the access key ID will be mapped to.",
|
||||||
secretAccessKey: "The name of the secret that the rotated secret access key will be mapped to."
|
secretAccessKey: "The name of the secret that the rotated secret access key will be mapped to."
|
||||||
|
},
|
||||||
|
OKTA_CLIENT_SECRET: {
|
||||||
|
clientId: "The name of the secret that the client ID will be mapped to.",
|
||||||
|
clientSecret: "The name of the secret that the rotated client secret will be mapped to."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -204,6 +204,17 @@ const envSchema = z
|
|||||||
WORKFLOW_SLACK_CLIENT_SECRET: zpStr(z.string().optional()),
|
WORKFLOW_SLACK_CLIENT_SECRET: zpStr(z.string().optional()),
|
||||||
ENABLE_MSSQL_SECRET_ROTATION_ENCRYPT: zodStrBool.default("true"),
|
ENABLE_MSSQL_SECRET_ROTATION_ENCRYPT: zodStrBool.default("true"),
|
||||||
|
|
||||||
|
// Special Detection Feature
|
||||||
|
PARAMS_FOLDER_SECRET_DETECTION_PATHS: zpStr(
|
||||||
|
z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.transform((val) => {
|
||||||
|
if (!val) return undefined;
|
||||||
|
return JSON.parse(val) as { secretPath: string; projectId: string }[];
|
||||||
|
})
|
||||||
|
),
|
||||||
|
|
||||||
// HSM
|
// HSM
|
||||||
HSM_LIB_PATH: zpStr(z.string().optional()),
|
HSM_LIB_PATH: zpStr(z.string().optional()),
|
||||||
HSM_PIN: zpStr(z.string().optional()),
|
HSM_PIN: zpStr(z.string().optional()),
|
||||||
@@ -261,10 +272,26 @@ const envSchema = z
|
|||||||
// gcp app
|
// gcp app
|
||||||
INF_APP_CONNECTION_GCP_SERVICE_ACCOUNT_CREDENTIAL: zpStr(z.string().optional()),
|
INF_APP_CONNECTION_GCP_SERVICE_ACCOUNT_CREDENTIAL: zpStr(z.string().optional()),
|
||||||
|
|
||||||
// azure app
|
// Legacy Single Multi Purpose Azure App Connection
|
||||||
INF_APP_CONNECTION_AZURE_CLIENT_ID: zpStr(z.string().optional()),
|
INF_APP_CONNECTION_AZURE_CLIENT_ID: zpStr(z.string().optional()),
|
||||||
INF_APP_CONNECTION_AZURE_CLIENT_SECRET: zpStr(z.string().optional()),
|
INF_APP_CONNECTION_AZURE_CLIENT_SECRET: zpStr(z.string().optional()),
|
||||||
|
|
||||||
|
// Azure App Configuration App Connection
|
||||||
|
INF_APP_CONNECTION_AZURE_APP_CONFIGURATION_CLIENT_ID: zpStr(z.string().optional()),
|
||||||
|
INF_APP_CONNECTION_AZURE_APP_CONFIGURATION_CLIENT_SECRET: zpStr(z.string().optional()),
|
||||||
|
|
||||||
|
// Azure Key Vault App Connection
|
||||||
|
INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_ID: zpStr(z.string().optional()),
|
||||||
|
INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_SECRET: zpStr(z.string().optional()),
|
||||||
|
|
||||||
|
// Azure Client Secrets App Connection
|
||||||
|
INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_ID: zpStr(z.string().optional()),
|
||||||
|
INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_SECRET: zpStr(z.string().optional()),
|
||||||
|
|
||||||
|
// Azure DevOps App Connection
|
||||||
|
INF_APP_CONNECTION_AZURE_DEVOPS_CLIENT_ID: zpStr(z.string().optional()),
|
||||||
|
INF_APP_CONNECTION_AZURE_DEVOPS_CLIENT_SECRET: zpStr(z.string().optional()),
|
||||||
|
|
||||||
// datadog
|
// datadog
|
||||||
SHOULD_USE_DATADOG_TRACER: zodStrBool.default("false"),
|
SHOULD_USE_DATADOG_TRACER: zodStrBool.default("false"),
|
||||||
DATADOG_PROFILING_ENABLED: zodStrBool.default("false"),
|
DATADOG_PROFILING_ENABLED: zodStrBool.default("false"),
|
||||||
@@ -341,7 +368,24 @@ const envSchema = z
|
|||||||
isHsmConfigured:
|
isHsmConfigured:
|
||||||
Boolean(data.HSM_LIB_PATH) && Boolean(data.HSM_PIN) && Boolean(data.HSM_KEY_LABEL) && data.HSM_SLOT !== undefined,
|
Boolean(data.HSM_LIB_PATH) && Boolean(data.HSM_PIN) && Boolean(data.HSM_KEY_LABEL) && data.HSM_SLOT !== undefined,
|
||||||
samlDefaultOrgSlug: data.DEFAULT_SAML_ORG_SLUG,
|
samlDefaultOrgSlug: data.DEFAULT_SAML_ORG_SLUG,
|
||||||
SECRET_SCANNING_ORG_WHITELIST: data.SECRET_SCANNING_ORG_WHITELIST?.split(",")
|
SECRET_SCANNING_ORG_WHITELIST: data.SECRET_SCANNING_ORG_WHITELIST?.split(","),
|
||||||
|
PARAMS_FOLDER_SECRET_DETECTION_ENABLED: (data.PARAMS_FOLDER_SECRET_DETECTION_PATHS?.length ?? 0) > 0,
|
||||||
|
INF_APP_CONNECTION_AZURE_DEVOPS_CLIENT_ID:
|
||||||
|
data.INF_APP_CONNECTION_AZURE_DEVOPS_CLIENT_ID || data.INF_APP_CONNECTION_AZURE_CLIENT_ID,
|
||||||
|
INF_APP_CONNECTION_AZURE_DEVOPS_CLIENT_SECRET:
|
||||||
|
data.INF_APP_CONNECTION_AZURE_DEVOPS_CLIENT_SECRET || data.INF_APP_CONNECTION_AZURE_CLIENT_SECRET,
|
||||||
|
INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_ID:
|
||||||
|
data.INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_ID || data.INF_APP_CONNECTION_AZURE_CLIENT_ID,
|
||||||
|
INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_SECRET:
|
||||||
|
data.INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_SECRET || data.INF_APP_CONNECTION_AZURE_CLIENT_SECRET,
|
||||||
|
INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_ID:
|
||||||
|
data.INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_ID || data.INF_APP_CONNECTION_AZURE_CLIENT_ID,
|
||||||
|
INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_SECRET:
|
||||||
|
data.INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_SECRET || data.INF_APP_CONNECTION_AZURE_CLIENT_SECRET,
|
||||||
|
INF_APP_CONNECTION_AZURE_APP_CONFIGURATION_CLIENT_ID:
|
||||||
|
data.INF_APP_CONNECTION_AZURE_APP_CONFIGURATION_CLIENT_ID || data.INF_APP_CONNECTION_AZURE_CLIENT_ID,
|
||||||
|
INF_APP_CONNECTION_AZURE_APP_CONFIGURATION_CLIENT_SECRET:
|
||||||
|
data.INF_APP_CONNECTION_AZURE_APP_CONFIGURATION_CLIENT_SECRET || data.INF_APP_CONNECTION_AZURE_CLIENT_SECRET
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export type TEnvConfig = Readonly<z.infer<typeof envSchema>>;
|
export type TEnvConfig = Readonly<z.infer<typeof envSchema>>;
|
||||||
@@ -451,15 +495,54 @@ export const overwriteSchema: {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
azure: {
|
azureAppConfiguration: {
|
||||||
name: "Azure",
|
name: "Azure App Configuration",
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
key: "INF_APP_CONNECTION_AZURE_CLIENT_ID",
|
key: "INF_APP_CONNECTION_AZURE_APP_CONFIGURATION_CLIENT_ID",
|
||||||
description: "The Application (Client) ID of your Azure application."
|
description: "The Application (Client) ID of your Azure application."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "INF_APP_CONNECTION_AZURE_CLIENT_SECRET",
|
key: "INF_APP_CONNECTION_AZURE_APP_CONFIGURATION_CLIENT_SECRET",
|
||||||
|
description: "The Client Secret of your Azure application."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
azureKeyVault: {
|
||||||
|
name: "Azure Key Vault",
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
key: "INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_ID",
|
||||||
|
description: "The Application (Client) ID of your Azure application."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "INF_APP_CONNECTION_AZURE_KEY_VAULT_CLIENT_SECRET",
|
||||||
|
description: "The Client Secret of your Azure application."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
azureClientSecrets: {
|
||||||
|
name: "Azure Client Secrets",
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
key: "INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_ID",
|
||||||
|
description: "The Application (Client) ID of your Azure application."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "INF_APP_CONNECTION_AZURE_CLIENT_SECRETS_CLIENT_SECRET",
|
||||||
|
description: "The Client Secret of your Azure application."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
azureDevOps: {
|
||||||
|
name: "Azure DevOps",
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
key: "INF_APP_CONNECTION_AZURE_DEVOPS_CLIENT_ID",
|
||||||
|
description: "The Application (Client) ID of your Azure application."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "INF_APP_CONNECTION_AZURE_DEVOPS_CLIENT_SECRET",
|
||||||
description: "The Client Secret of your Azure application."
|
description: "The Client Secret of your Azure application."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@@ -14,7 +14,7 @@ import { TSuperAdminDALFactory } from "@app/services/super-admin/super-admin-dal
|
|||||||
import { ADMIN_CONFIG_DB_UUID } from "@app/services/super-admin/super-admin-service";
|
import { ADMIN_CONFIG_DB_UUID } from "@app/services/super-admin/super-admin-service";
|
||||||
|
|
||||||
import { isBase64 } from "../../base64";
|
import { isBase64 } from "../../base64";
|
||||||
import { getConfig } from "../../config/env";
|
import { getConfig, TEnvConfig } from "../../config/env";
|
||||||
import { CryptographyError } from "../../errors";
|
import { CryptographyError } from "../../errors";
|
||||||
import { logger } from "../../logger";
|
import { logger } from "../../logger";
|
||||||
import { asymmetricFipsValidated } from "./asymmetric-fips";
|
import { asymmetricFipsValidated } from "./asymmetric-fips";
|
||||||
@@ -93,19 +93,25 @@ const cryptographyFactory = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const verifyFipsLicense = (licenseService: Pick<TLicenseServiceFactory, "onPremFeatures">) => {
|
const verifyFipsLicense = (licenseService: Pick<TLicenseServiceFactory, "onPremFeatures">) => {
|
||||||
if (isFipsModeEnabled({ skipInitializationCheck: true }) && !licenseService.onPremFeatures?.fips) {
|
const appCfg = getConfig();
|
||||||
|
|
||||||
|
if (
|
||||||
|
!appCfg.isDevelopmentMode &&
|
||||||
|
isFipsModeEnabled({ skipInitializationCheck: true }) &&
|
||||||
|
!licenseService.onPremFeatures?.fips
|
||||||
|
) {
|
||||||
throw new CryptographyError({
|
throw new CryptographyError({
|
||||||
message: "FIPS mode is enabled but your license does not include FIPS support. Please contact support."
|
message: "FIPS mode is enabled but your license does not include FIPS support. Please contact support."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const $setFipsModeEnabled = (enabled: boolean) => {
|
const $setFipsModeEnabled = (enabled: boolean, envCfg?: Pick<TEnvConfig, "ENCRYPTION_KEY">) => {
|
||||||
// If FIPS is enabled, we need to validate that the ENCRYPTION_KEY is in a base64 format, and is a 256-bit key.
|
// If FIPS is enabled, we need to validate that the ENCRYPTION_KEY is in a base64 format, and is a 256-bit key.
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
crypto.setFips(true);
|
crypto.setFips(true);
|
||||||
|
|
||||||
const appCfg = getConfig();
|
const appCfg = envCfg || getConfig();
|
||||||
|
|
||||||
if (appCfg.ENCRYPTION_KEY) {
|
if (appCfg.ENCRYPTION_KEY) {
|
||||||
// we need to validate that the ENCRYPTION_KEY is a base64 encoded 256-bit key
|
// we need to validate that the ENCRYPTION_KEY is a base64 encoded 256-bit key
|
||||||
@@ -135,14 +141,14 @@ const cryptographyFactory = () => {
|
|||||||
$isInitialized = true;
|
$isInitialized = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const initialize = async (superAdminDAL: TSuperAdminDALFactory) => {
|
const initialize = async (superAdminDAL: TSuperAdminDALFactory, envCfg?: Pick<TEnvConfig, "ENCRYPTION_KEY">) => {
|
||||||
if ($isInitialized) {
|
if ($isInitialized) {
|
||||||
return isFipsModeEnabled();
|
return isFipsModeEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.FIPS_ENABLED !== "true") {
|
if (process.env.FIPS_ENABLED !== "true") {
|
||||||
logger.info("Cryptography module initialized in normal operation mode.");
|
logger.info("Cryptography module initialized in normal operation mode.");
|
||||||
$setFipsModeEnabled(false);
|
$setFipsModeEnabled(false, envCfg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,11 +158,11 @@ const cryptographyFactory = () => {
|
|||||||
if (serverCfg) {
|
if (serverCfg) {
|
||||||
if (serverCfg.fipsEnabled) {
|
if (serverCfg.fipsEnabled) {
|
||||||
logger.info("[FIPS]: Instance is configured for FIPS mode of operation. Continuing startup with FIPS enabled.");
|
logger.info("[FIPS]: Instance is configured for FIPS mode of operation. Continuing startup with FIPS enabled.");
|
||||||
$setFipsModeEnabled(true);
|
$setFipsModeEnabled(true, envCfg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
logger.info("[FIPS]: Instance age predates FIPS mode inception date. Continuing without FIPS.");
|
logger.info("[FIPS]: Instance age predates FIPS mode inception date. Continuing without FIPS.");
|
||||||
$setFipsModeEnabled(false);
|
$setFipsModeEnabled(false, envCfg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +171,7 @@ const cryptographyFactory = () => {
|
|||||||
// TODO(daniel): check if it's an enterprise deployment
|
// TODO(daniel): check if it's an enterprise deployment
|
||||||
|
|
||||||
// if there is no server cfg, and FIPS_MODE is `true`, its a fresh FIPS deployment. We need to set the fipsEnabled to true.
|
// if there is no server cfg, and FIPS_MODE is `true`, its a fresh FIPS deployment. We need to set the fipsEnabled to true.
|
||||||
$setFipsModeEnabled(true);
|
$setFipsModeEnabled(true, envCfg);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -14,6 +14,11 @@ export const blockLocalAndPrivateIpAddresses = async (url: string) => {
|
|||||||
if (appCfg.isDevelopmentMode) return;
|
if (appCfg.isDevelopmentMode) return;
|
||||||
|
|
||||||
const validUrl = new URL(url);
|
const validUrl = new URL(url);
|
||||||
|
|
||||||
|
if (validUrl.username || validUrl.password) {
|
||||||
|
throw new BadRequestError({ message: "URLs with user credentials (e.g., user:pass@) are not allowed" });
|
||||||
|
}
|
||||||
|
|
||||||
const inputHostIps: string[] = [];
|
const inputHostIps: string[] = [];
|
||||||
if (isIPv4(validUrl.hostname)) {
|
if (isIPv4(validUrl.hostname)) {
|
||||||
inputHostIps.push(validUrl.hostname);
|
inputHostIps.push(validUrl.hostname);
|
||||||
|
@@ -64,7 +64,9 @@ export enum QueueName {
|
|||||||
FolderTreeCheckpoint = "folder-tree-checkpoint",
|
FolderTreeCheckpoint = "folder-tree-checkpoint",
|
||||||
InvalidateCache = "invalidate-cache",
|
InvalidateCache = "invalidate-cache",
|
||||||
SecretScanningV2 = "secret-scanning-v2",
|
SecretScanningV2 = "secret-scanning-v2",
|
||||||
TelemetryAggregatedEvents = "telemetry-aggregated-events"
|
TelemetryAggregatedEvents = "telemetry-aggregated-events",
|
||||||
|
DailyReminders = "daily-reminders",
|
||||||
|
SecretReminderMigration = "secret-reminder-migration"
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum QueueJobs {
|
export enum QueueJobs {
|
||||||
@@ -104,7 +106,9 @@ export enum QueueJobs {
|
|||||||
SecretScanningV2SendNotification = "secret-scanning-v2-notification",
|
SecretScanningV2SendNotification = "secret-scanning-v2-notification",
|
||||||
CaOrderCertificateForSubscriber = "ca-order-certificate-for-subscriber",
|
CaOrderCertificateForSubscriber = "ca-order-certificate-for-subscriber",
|
||||||
PkiSubscriberDailyAutoRenewal = "pki-subscriber-daily-auto-renewal",
|
PkiSubscriberDailyAutoRenewal = "pki-subscriber-daily-auto-renewal",
|
||||||
TelemetryAggregatedEvents = "telemetry-aggregated-events"
|
TelemetryAggregatedEvents = "telemetry-aggregated-events",
|
||||||
|
DailyReminders = "daily-reminders",
|
||||||
|
SecretReminderMigration = "secret-reminder-migration"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TQueueJobTypes = {
|
export type TQueueJobTypes = {
|
||||||
@@ -291,6 +295,14 @@ export type TQueueJobTypes = {
|
|||||||
caType: CaType;
|
caType: CaType;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
[QueueName.DailyReminders]: {
|
||||||
|
name: QueueJobs.DailyReminders;
|
||||||
|
payload: undefined;
|
||||||
|
};
|
||||||
|
[QueueName.SecretReminderMigration]: {
|
||||||
|
name: QueueJobs.SecretReminderMigration;
|
||||||
|
payload: undefined;
|
||||||
|
};
|
||||||
[QueueName.PkiSubscriber]: {
|
[QueueName.PkiSubscriber]: {
|
||||||
name: QueueJobs.PkiSubscriberDailyAutoRenewal;
|
name: QueueJobs.PkiSubscriberDailyAutoRenewal;
|
||||||
payload: undefined;
|
payload: undefined;
|
||||||
@@ -390,6 +402,11 @@ export type TQueueServiceFactory = {
|
|||||||
startOffset?: number,
|
startOffset?: number,
|
||||||
endOffset?: number
|
endOffset?: number
|
||||||
) => Promise<{ key: string; name: string; id: string | null }[]>;
|
) => Promise<{ key: string; name: string; id: string | null }[]>;
|
||||||
|
getDelayedJobs: (
|
||||||
|
name: QueueName,
|
||||||
|
startOffset?: number,
|
||||||
|
endOffset?: number
|
||||||
|
) => Promise<{ delay: number; timestamp: number; repeatJobKey?: string; data?: unknown }[]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const queueServiceFactory = (
|
export const queueServiceFactory = (
|
||||||
@@ -552,6 +569,13 @@ export const queueServiceFactory = (
|
|||||||
return q.getRepeatableJobs(startOffset, endOffset);
|
return q.getRepeatableJobs(startOffset, endOffset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getDelayedJobs: TQueueServiceFactory["getDelayedJobs"] = (name, startOffset, endOffset) => {
|
||||||
|
const q = queueContainer[name];
|
||||||
|
if (!q) throw new Error(`Queue '${name}' not initialized`);
|
||||||
|
|
||||||
|
return q.getDelayed(startOffset, endOffset);
|
||||||
|
};
|
||||||
|
|
||||||
const stopRepeatableJobByJobId: TQueueServiceFactory["stopRepeatableJobByJobId"] = async (name, jobId) => {
|
const stopRepeatableJobByJobId: TQueueServiceFactory["stopRepeatableJobByJobId"] = async (name, jobId) => {
|
||||||
const q = queueContainer[name];
|
const q = queueContainer[name];
|
||||||
const job = await q.getJob(jobId);
|
const job = await q.getJob(jobId);
|
||||||
@@ -598,6 +622,7 @@ export const queueServiceFactory = (
|
|||||||
stopJobById,
|
stopJobById,
|
||||||
stopJobByIdPg,
|
stopJobByIdPg,
|
||||||
getRepeatableJobs,
|
getRepeatableJobs,
|
||||||
|
getDelayedJobs,
|
||||||
startPg,
|
startPg,
|
||||||
queuePg,
|
queuePg,
|
||||||
schedulePg
|
schedulePg
|
||||||
|
43
backend/src/server/lib/cookie.ts
Normal file
43
backend/src/server/lib/cookie.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { FastifyReply } from "fastify";
|
||||||
|
|
||||||
|
import { getConfig } from "@app/lib/config/env";
|
||||||
|
import { logger } from "@app/lib/logger";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `aod` (Auth Origin Domain) cookie is used to store the origin domain of the application when user was last authenticated.
|
||||||
|
* This is useful for determining the target domain for authentication redirects, especially in cloud deployments.
|
||||||
|
* It is set only in cloud mode to ensure that the cookie is shared across subdomains.
|
||||||
|
*/
|
||||||
|
export function addAuthOriginDomainCookie(res: FastifyReply) {
|
||||||
|
try {
|
||||||
|
const appCfg = getConfig();
|
||||||
|
|
||||||
|
// Only set the cookie if the app is running in cloud mode
|
||||||
|
if (!appCfg.isCloud) return;
|
||||||
|
|
||||||
|
const siteUrl = appCfg.SITE_URL!;
|
||||||
|
let domain: string;
|
||||||
|
|
||||||
|
const { hostname } = new URL(siteUrl);
|
||||||
|
|
||||||
|
const parts = hostname.split(".");
|
||||||
|
|
||||||
|
if (parts.length >= 2) {
|
||||||
|
// For `app.infisical.com` => `.infisical.com`
|
||||||
|
domain = `.${parts.slice(-2).join(".")}`;
|
||||||
|
} else {
|
||||||
|
// If somehow only "example", fallback to itself
|
||||||
|
domain = `.${hostname}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
void res.setCookie("aod", siteUrl, {
|
||||||
|
domain,
|
||||||
|
path: "/",
|
||||||
|
sameSite: "strict",
|
||||||
|
httpOnly: false,
|
||||||
|
secure: appCfg.HTTPS_ENABLED
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error, "Failed to set auth origin domain cookie");
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user