Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions app/controlplane/api/controlplane/v1/response_messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/controlplane/api/controlplane/v1/response_messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ message CASBackendItem {
google.protobuf.Timestamp updated_at = 13;
// Wether it's the fallback backend in the organization
bool fallback = 14;
// Whether this backend is provisioned and operated by Chainloop using
bool is_managed = 15;

message Limits {
// Max number of bytes allowed to be stored in this backend
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/controlplane/internal/service/casbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func bizCASBackendToPb(in *biz.CASBackend) *pb.CASBackendItem {
Default: in.Default,
Fallback: in.Fallback,
IsInline: in.Inline,
IsManaged: in.Managed,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd say that only users with the INSTANCE_ADMIN role can set this flag to true. what do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nodody should do it no? Isn't setting this value out of the scope of the PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes, nobody should have access to that, it should be set automatically by the backend during auto provisioning

}

if in.Limits != nil {
Expand Down
13 changes: 13 additions & 0 deletions app/controlplane/pkg/biz/casbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type CASBackend struct {
Inline bool
// It's a fallback backend, used when the default backend is unreachable
Fallback bool
// Managed indicates this backend is provisioned and operated by Chainloop
Managed bool

Limits *CASBackendLimits
}
Expand All @@ -88,6 +90,7 @@ type CASBackendOpts struct {
Provider CASBackendProvider
Default *bool
Fallback *bool
Managed *bool
ValidationStatus CASBackendValidationStatus
ValidationError *string
}
Expand Down Expand Up @@ -450,6 +453,11 @@ func (uc *CASBackendUseCase) Update(ctx context.Context, orgID, id string, descr
return nil, NewErrValidationStr("inline backends cannot have their max_bytes updated")
}

// Managed backends are owned and operated by Chainloop and cannot be modified by users.
if before.Managed {
return nil, NewErrValidationStr("managed CAS backends cannot be modified")
}

// Validate max_bytes if provided
if maxBytes != nil && *maxBytes < MinCASBackendMaxBytes {
return nil, NewErrValidationStr(fmt.Sprintf("max_bytes must be at least %s", bytefmt.ByteSize(uint64(MinCASBackendMaxBytes))))
Expand Down Expand Up @@ -612,6 +620,11 @@ func (uc *CASBackendUseCase) SoftDelete(ctx context.Context, orgID, id string) e
return NewErrValidation(errors.New("can't delete the inline CAS backend"))
}

// Prevent deletion of managed backends - they are owned and operated by Chainloop
if backend.Managed {
return NewErrValidation(errors.New("can't delete a managed CAS backend"))
}

if err := uc.repo.SoftDelete(ctx, backendUUID); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions app/controlplane/pkg/data/casbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (r *CASBackendRepo) Create(ctx context.Context, opts *biz.CASBackendCreateO
SetNillableFallback(opts.Fallback).
SetProvider(opts.Provider).
SetNillableDefault(opts.Default).
SetNillableManaged(opts.Managed).
SetSecretName(opts.SecretName).
SetMaxBlobSizeBytes(opts.MaxBytes).
Save(ctx)
Expand Down Expand Up @@ -404,6 +405,7 @@ func entCASBackendToBiz(backend *ent.CASBackend) *biz.CASBackend {
Inline: backend.Provider == biz.CASBackendInline,
Limits: limits,
Fallback: backend.Fallback,
Managed: backend.Managed,
}

if org := backend.Edges.Organization; org != nil {
Expand Down
13 changes: 12 additions & 1 deletion app/controlplane/pkg/data/ent/casbackend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions app/controlplane/pkg/data/ent/casbackend/casbackend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions app/controlplane/pkg/data/ent/casbackend/where.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading