Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 54
feat(artifact-cas): verify uploaded content against the declared digest#3365
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -25,6 +25,7 @@ import ( | ||
| "github.com/chainloop-dev/chainloop/app/artifact-cas/internal/conf" | ||
| "github.com/chainloop-dev/chainloop/app/artifact-cas/internal/server" | ||
| "github.com/chainloop-dev/chainloop/app/artifact-cas/internal/service" | ||
| backend "github.com/chainloop-dev/chainloop/pkg/blobmanager" | ||
| "github.com/chainloop-dev/chainloop/pkg/credentials" | ||
| "github.com/chainloop-dev/chainloop/pkg/credentials/manager" | ||
| @@ -121,6 +122,12 @@ func main() { | ||
| _ = logger.Log(log.LevelInfo, "msg", "starting artifact-cas service", "version", Version) | ||
| // Ensure the upload staging directory exists and sweep any files a previous | ||
| // crash left behind, so verification always starts from a clean volume. | ||
| if err := prepareStagingDir(&bc, logger); err != nil { | ||
| panic(err) | ||
| } | ||
| flush, err := initSentry(&bc, logger) | ||
| defer flush() | ||
| if err != nil { | ||
| @@ -152,6 +159,31 @@ func newProtoValidator() (protovalidate.Validator, error) { | ||
| return protovalidate.New() | ||
| } | ||
| // prepareStagingDir resolves the upload staging directory (falling back to the | ||
| // OS temp dir when unconfigured — dev only; production mounts a dedicated | ||
| // volume), creates it, and removes any leftover staging files from a previous | ||
| // run. It must use the same directory the service is configured with (see | ||
| // serviceOpts / conf.staging_dir). | ||
| func prepareStagingDir(bc *conf.Bootstrap, logger log.Logger) error { | ||
| dir := bc.GetStagingDir() | ||
| if dir == "" { | ||
| dir = os.TempDir() | ||
| _ = logger.Log(log.LevelWarn, "msg", "staging_dir not configured, falling back to OS temp dir (dev only)", "dir", dir) | ||
| } | ||
| if err := os.MkdirAll(dir, 0o700); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: When the configured or fallback staging directory exists but is not writable, Prompt for AI agentsMember There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this work on scrach container? | ||
| return err | ||
| } | ||
| if _, err := service.SweepStagingDir(dir, servicelogger.ScopedHelper(logger, "staging")); err != nil { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you sweeping on boot that might cause problems booting, I'd keep startup process as limited as possible | ||
| // A sweep failure is not fatal: the deferred per-upload cleanup still | ||
| // applies, so log and continue rather than blocking startup. | ||
| _ = logger.Log(log.LevelWarn, "msg", "failed to sweep staging dir", "dir", dir, "error", err.Error()) | ||
| } | ||
| return nil | ||
| } | ||
| func initSentry(c *conf.Bootstrap, logger log.Logger) (cleanupFunc func(), err error) { | ||
| cleanupFunc = func() { | ||
| sentry.Flush(2 * time.Second) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
fail here do not fallback