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

Add flag to follow symlinks when running opa build #6800

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tjons
Copy link
Contributor

@tjons tjons commented Jun 7, 2024

Why the changes in this PR are needed?

Per #6495, it is important to users using build systems like babel to allow opa build to include symlinked files in the bundle directory. Bazel and other build tools create sandboxes of symlinked files before building. As it stands today, opa build only includes regular files and directories by default.

What are the changes in this PR?

This PR adds a boolean flag, --follow-symlinks to the opa build command to allow users to build directories with symlinked files, and have the contents of those symlinked files included in the built bundle.

Notes to assist PR review:

I've included tests for the build command but would appreciate a critical eye as to any other areas that could use testing. Also, I've kept the symlink changes as constrained to the build features as possible, but there are many layers of method calls to get to the core filesystem loading logic, so any ideas for cleaning up this code is welcome.

Further comments:

@tjons tjons force-pushed the tjons/6495-symlinks-building-bundles branch from 32341ef to 5de7d4b Compare June 7, 2024 00:48
Copy link

netlify bot commented Jun 7, 2024

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 32341ef
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/666258dc4105820008e9ebae
😎 Deploy Preview https://deploy-preview-6800--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Signed-off-by: Tyler Schade <[email protected]>
@tjons tjons force-pushed the tjons/6495-symlinks-building-bundles branch from b58f28c to 6ee5e4c Compare June 7, 2024 00:50
Copy link

netlify bot commented Jun 7, 2024

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit b58f28c
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/666258ff5f50be0008760453
😎 Deploy Preview https://deploy-preview-6800--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tjons tjons force-pushed the tjons/6495-symlinks-building-bundles branch from 8329087 to 6bd3b39 Compare June 7, 2024 15:56
Copy link
Contributor

@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

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

Thank you! 😃
Just a couple of comments/questions.

}

// GetBundleDirectoryLoaderFS returns a bundle directory loader which can be used to load
// files in the directory.
func GetBundleDirectoryLoaderFS(fsys fs.FS, path string, filter Filter) (bundle.DirectoryLoader, bool, error) {
func GetBundleDirectoryLoaderFS(fsys fs.FS, path string, filter Filter, followSymlinks bool) (bundle.DirectoryLoader, bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be a breaking change for anyone using this public function directly, although probably unlikely. Given that we also add WithFollowSymlinks(), couldn't callers simply use that on the returned value instead?

@@ -188,6 +190,12 @@ func (fl *fileLoader) WithRegoVersion(version ast.RegoVersion) FileLoader {
return fl
}

// WithFollowSymLinks enables or disables following symlinks when loading files
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// WithFollowSymLinks enables or disables following symlinks when loading files
// WithFollowSymlinks enables or disables following symlinks when loading files


params := newBuildParams()
params.outputFile = path.Join(rootDir, "test.tar.gz")
params.bundleMode = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we drop This? Reading in bundle-mode doesn't seem like a requirement.

@@ -238,6 +239,7 @@ against OPA v0.22.0:
buildCommand.Flags().VarP(&buildParams.revision, "revision", "r", "set output bundle revision")
buildCommand.Flags().StringVarP(&buildParams.outputFile, "output", "o", "bundle.tar.gz", "set the output filename")
buildCommand.Flags().StringVar(&buildParams.ns, "partial-namespace", "partial", "set the namespace to use for partially evaluated files in an optimized bundle")
buildCommand.Flags().BoolVar(&buildParams.followSymlinks, "follow-symlinks", false, "follow symlinks in the input directory when building the bundle")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we limited to only following symlinks in directories, and not also direct paths to symlinks? Doesn't look like that'd be the case 🤔; i.e. the FileLoader created and called in LoadPathsForRegoVersion looks like it'd follow links.
If this isn't a limitation, we should update this description to say that symlinks in the provided set of paths are followed (not just dirs). And we should update the test to assert this (or add an additional test).

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.

None yet

2 participants