-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add new config param to allow GroupExec perm for the SecretBackend command #6298
Conversation
5f889b5
to
850895d
Compare
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.
The biggest issue is the lack of read permission for a script.
Otherwise, I left some cosmetics suggestions.
855c4c7
to
fee5f73
Compare
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 is only one error message which is misleading.
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.
A few comments. But overall if security is OK with this I think we're almost good to merge.
releasenotes/notes/Add-Group-exec-perm-for-the-SecretBackend-command-a7fbe1ece1fad50b.yaml
Show resolved
Hide resolved
Once this is merged let's not forget to update the official doc to explain when, why and how to enable this option : https://docs.datadoghq.com/agent/guide/secrets-management/?tab=linux |
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.
Left a few nits inline, once addressed LGTM 👍
Let's have a security review as well
releasenotes/notes/Add-Group-exec-perm-for-the-SecretBackend-command-a7fbe1ece1fad50b.yaml
Outdated
Show resolved
Hide resolved
79fe747
to
44fcf25
Compare
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.
I think it's almost good to go for me.
releasenotes/notes/Add-Group-exec-perm-for-the-SecretBackend-command-a7fbe1ece1fad50b.yaml
Show resolved
Hide resolved
releasenotes-dca/Add-Group-exec-perm-for-the-SecretBackend-command-a7fbe1ece1fad50b.yaml
Outdated
Show resolved
Hide resolved
10af196
to
9550d63
Compare
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 nit but looks good otherwise
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.
Nits, and one comment on the logged warning, but the logic LGTM! 👍 (and thanks for the additional unit tests!)
pkg/secrets/check_rights_nix.go
Outdated
} | ||
|
||
// checking that we own the executable | ||
usr, err := user.Current() | ||
userGroups, err := usr.GroupIds() | ||
if err != nil { | ||
return fmt.Errorf("can't query current user UID: %s", err) |
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.
return fmt.Errorf("can't query current user UID: %s", err) | |
return fmt.Errorf("can't query current user's GIDs: %s", err) |
releasenotes-dca/Add-Group-exec-perm-for-the-SecretBackend-command-a7fbe1ece1fad50b.yaml
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.
Other than warning that a script is executable but not readable (very minor comment), and adding tests for checking UID, I see no security issue. Thanks for all your work!
pkg/secrets/check_rights_nix.go
Outdated
return nil | ||
} | ||
|
||
// checkUserPermission check that only the current User or one of his group can exec the path |
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.
// checkUserPermission check that only the current User or one of his group can exec the path | |
// checkGroupPermission check that only the current User or one of his group can exec the path |
pkg/secrets/check_rights_windows.go
Outdated
@@ -24,7 +24,9 @@ var ( | |||
|
|||
// checkRights check that the given filename has access controls set only for | |||
// Administrator, Local System and the datadog user. | |||
func checkRights(filename string) error { | |||
func checkRights(filename string, _ bool) 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.
Maybe instead of ignoring the bool here, return an error if it is true?
pkg/secrets/check_rights_nix.go
Outdated
isUserFile = true | ||
} | ||
// If the file is not own by the user, lets check for on of his groups | ||
if !isUserFile { |
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.
if isUserFile
, you might wish to check that user can exec (check that stat.Mode&syscall.S_IXUSR == 0
is not an issue like in checkUserPermission
)
require.Nil(t, os.Chmod(tmpfile.Name(), 0600)) | ||
require.NotNil(t, checkRights(tmpfile.Name())) | ||
require.NotNil(t, checkRights(tmpfile.Name(), allowGroupExec)) | ||
|
||
// group should have no right | ||
require.Nil(t, os.Chmod(tmpfile.Name(), 0710)) |
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.
Consider adding a separate 0720
test here (group can write)
|
||
// group should have no right | ||
require.Nil(t, os.Chmod(tmpfile.Name(), 0710)) | ||
require.NotNil(t, checkRights(tmpfile.Name())) | ||
require.NotNil(t, checkRights(tmpfile.Name(), allowGroupExec)) | ||
|
||
// other should have no right | ||
require.Nil(t, os.Chmod(tmpfile.Name(), 0701)) |
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.
Consider adding a separate 0702
test here (others can write)
require.Nil(t, os.Chmod(tmpfile.Name(), 0770)) | ||
require.NotNil(t, checkRights(tmpfile.Name(), allowGroupExec)) | ||
|
||
// other should have no right |
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.
Consider adding a separate 0702
test here (others can write)
When the agent runs in a container environment, the process can be executed with a "random" uid (for security reason). To allow the execution of the secret-backend command packaged inside the docker image. the secret-backend script need to allow the execution of a group uid. The new option "secret_backend_command_allow_group_exec_perm" allow to change the behaviour of the `checkRights()` function and allow GroupExecPerm. We update only the dockerfile configuration for the cluster-agent. because the "agent" process needs to run as root, so the described setup is not possible with the agent image: * change the readsecret.sh permission to 510 * set DD_SECRET_BACKEND_COMMAND_ALLOW_GROUP_EXEC_PERM env var to true by default in the cluster-agent entry-point
Co-authored-by: Lénaïc Huard <L3n41c@users.noreply.github.com>
Co-authored-by: Olivier Vielpeau <olivielpeau@users.noreply.github.com>
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Signed-off-by: cedric lamoriniere <cedric.lamoriniere@datadoghq.com>
Co-authored-by: maxime mouial <hush-hush@users.noreply.github.com>
Co-authored-by: Olivier Vielpeau <olivielpeau@users.noreply.github.com>
Signed-off-by: cedric lamoriniere <cedric.lamoriniere@datadoghq.com>
f587136
to
1c431ca
Compare
What does this PR do?
To allow the execution of the secret-backend command packaged inside
the docker image. the secret-backend script need to allow the execution
of a group uid.
The new option "secret_backend_command_allow_group_exec_perm" allow to
change the behaviour of the
checkRights()
function and allow GroupExecPerm.We update only the dockerfile configuration for the cluster-agent. because
the "agent" process needs to run as root, so the described setup is not possible
with the agent image:
by default in the cluster-agent entry-point
Motivation
When the agent runs in a container environment, the process can be
executed with a "random" uid (for security reason)
Additional Notes
Anything else we should know when reviewing?
Describe your test plan
Start the
Cluster-Agent
and use the "secret-backend" script packaged in the imagereadSecret.py
. TheCluster-Agent
should not return a file permission check error.