-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Environment variables in admin panel (read only) - backend #9943
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR implements a secure environment variables management system in the admin panel, allowing read-only access to configuration settings with proper grouping and sensitive data handling.
- Added
getEnvironmentVariablesGrouped
GraphQL query with authentication guards and sensitivity control inadmin-panel.resolver.ts
- Introduced
@EnvironmentVariablesMetadata
decorator inenvironment-variables-metadata.decorator.ts
for organizing variables with groups, descriptions, and sensitivity flags - Created hierarchical DTOs in
environment-variables.output.ts
to structure variables into logical groups and subgroups - Added
getAll
method inenvironment.service.ts
with secure handling of sensitive values through masking - Organized environment variables into clear categories with
EnvironmentVariablesGroup
andEnvironmentVariablesSubGroup
enums
11 file(s) reviewed, 13 comment(s)
Edit PR Review Bot Settings | Greptile
packages/twenty-server/src/engine/core-modules/admin-panel/admin-panel.resolver.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/admin-panel/admin-panel.service.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/admin-panel/admin-panel.service.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/admin-panel/dtos/environment-variables.output.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/admin-panel/dtos/environment-variables.output.ts
Outdated
Show resolved
Hide resolved
...nty-server/src/engine/core-modules/environment/enums/environment-variables-sub-group.enum.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/environment/environment.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/admin-panel/admin-panel.service.ts
Outdated
Show resolved
Hide resolved
...r/src/engine/core-modules/environment/decorators/environment-variables-metadata.decorator.ts
Outdated
Show resolved
Hide resolved
...r/src/engine/core-modules/environment/decorators/environment-variables-metadata.decorator.ts
Outdated
Show resolved
Hide resolved
...r/src/engine/core-modules/environment/decorators/environment-variables-metadata.decorator.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, looking forward to seeing how this will look!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
(updates since last review)
This PR continues the implementation of the environment variables management system in the admin panel. Here are the key new changes since the last review:
- Added frontend GraphQL types in
graphql.tsx
for environment variables querying and display - Integrated
useGetEnvironmentVariablesGroupedQuery
hook inSettingsAdminContent.tsx
for fetching environment data - Implemented masking strategies in
environment-variable-mask-sensitive-data.util.ts
for secure handling of sensitive values - Added typed reflection support in
typed-reflect.ts
for environment variable metadata handling
A few important points to note:
- There's a debug
console.log
inSettingsAdminContent.tsx
that should be removed before merging - The UI implementation for displaying the environment variables is not yet complete
- The validator in the environment variables metadata decorator always returns true without validation
The changes maintain the secure and organized approach established in the previous review while adding the necessary frontend infrastructure.
18 file(s) reviewed, 18 comment(s)
Edit PR Review Bot Settings | Greptile
packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminContent.tsx
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminContent.tsx
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/admin-panel/admin-panel.resolver.ts
Show resolved
Hide resolved
...nty-front/src/modules/settings/admin-panel/graphql/queries/getEnvironmentVariablesGrouped.ts
Outdated
Show resolved
Hide resolved
...nty-front/src/modules/settings/admin-panel/graphql/queries/getEnvironmentVariablesGrouped.ts
Outdated
Show resolved
Hide resolved
const allEnvVarNames = | ||
Reflect.getMetadata( | ||
ENVIRONMENT_VARIABLES_METADATA_DECORATOR_NAMES_KEY, | ||
EnvironmentVariables, | ||
) || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider caching the metadata result since it won't change during runtime and reflection operations are expensive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
const varMaskingConfig = | ||
ENVIRONMENT_VARIABLES_MASKING_CONFIG[ | ||
key as keyof typeof ENVIRONMENT_VARIABLES_MASKING_CONFIG | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Add error handling for invalid masking config access. TypeScript casting doesn't guarantee runtime safety
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
...r/src/engine/core-modules/environment/utils/environment-variable-mask-sensitive-data.util.ts
Outdated
Show resolved
Hide resolved
...r/src/engine/core-modules/environment/utils/environment-variable-mask-sensitive-data.util.ts
Outdated
Show resolved
Hide resolved
const url = new URL(value); | ||
|
||
if (url.password) { | ||
url.password = '********'; | ||
} | ||
if (url.username) { | ||
url.username = '********'; | ||
} | ||
|
||
return url.toString(); | ||
} catch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: URL parsing silently returns unmasked value on invalid URLs. This could expose sensitive data if the string contains credentials but isn't a valid URL. Consider additional validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, nice code thank you. I have left some comments
packages/twenty-server/src/engine/core-modules/admin-panel/admin-panel.service.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/admin-panel/dtos/environment-variables.output.ts
Outdated
Show resolved
Hide resolved
...server/src/engine/core-modules/environment/constants/environment-variables-group-position.ts
Show resolved
Hide resolved
...server/src/engine/core-modules/environment/constants/environment-variables-masking-config.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/environment/environment.service.ts
Show resolved
Hide resolved
...r/src/engine/core-modules/environment/utils/environment-variable-mask-sensitive-data.util.ts
Show resolved
Hide resolved
...r/src/engine/core-modules/environment/utils/environment-variable-mask-sensitive-data.util.ts
Outdated
Show resolved
Hide resolved
} | ||
|
||
default: | ||
return value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, or throw error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't in this case !? If that env var is not in maskConfig it will return its value
...nty-front/src/modules/settings/admin-panel/graphql/queries/getEnvironmentVariablesGrouped.ts
Outdated
Show resolved
Hide resolved
.../twenty-server/src/engine/core-modules/environment/enums/environment-variables-group.enum.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few comments but good for me you can merge when you feel it's good! Thank you
packages/twenty-server/src/engine/core-modules/admin-panel/admin-panel.spec.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One change then GTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm thank you!
Backend for twentyhq/core-team-issues#293
POC - #9903