Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Write files on Windows with a specific security descriptor #3595

Closed
wants to merge 2 commits into from

Conversation

amartinezfayo
Copy link
Member

The os.WriteFile function is used in SPIRE to write to a file with specific permission bits. This works well in Unix platforms but it doesn't allow to specify a specific security descriptor on Windows.
This PR adds two new functions to our diskutil package: WritePrivateFile and WritePubliclyReadableFile. Those functions have os-specific implementations that respect the intended permissions in each platform.

Fixes part of #3189.

Signed-off-by: Agustín Martínez Fayó <amartinezfayo@gmail.com>
Signed-off-by: Agustín Martínez Fayó <amartinezfayo@gmail.com>
Comment on lines +362 to +373
s.Require().NoError(diskutil.WritePubliclyReadableFile(fooPKCS1KeyPath, pem.EncodeToMemory(&pem.Block{
Type: "RSA PUBLIC KEY",
Bytes: fooPKCS1Bytes,
}), 0600))
})))

fooPKIXKeyPath := filepath.Join(s.dir, "foo-pkix.pem")
fooPKIXBytes, err := x509.MarshalPKIXPublicKey(s.fooKey.Public())
s.Require().NoError(err)
s.Require().NoError(os.WriteFile(fooPKIXKeyPath, pem.EncodeToMemory(&pem.Block{
s.Require().NoError(diskutil.WritePubliclyReadableFile(fooPKIXKeyPath, pem.EncodeToMemory(&pem.Block{
Type: "PUBLIC KEY",
Bytes: fooPKIXBytes,
}), 0600))
})))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amartinezfayo shouldn't we use WritePrivateFile instead of WritePubliclyReadableFile here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been back and forth thinking if the calls in the testing code should be replaced. I've just found that this is problematic in the integration tests so I'll go ahead and just use the new functions in the specific places that we need to honor the permissions when running SPIRE.

@amartinezfayo amartinezfayo deleted the win-writefile-sd branch March 1, 2023 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants