Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.
Merged
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
14 changes: 2 additions & 12 deletions apps/container-registry/internal/app/grpc-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,16 @@ func (g *grpcServer) CreateReadOnlyCredential(ctx context.Context, in *container
UserEmail: "",
}

creds, err := g.d.CreateCredential(regctx, entities.Credential{
creds, err := g.d.CreateAdminCredential(regctx, entities.Credential{
AccountName: in.AccountName,
Access: entities.RepoAccessReadOnly,
Expiration: entities.Expiration{Unit: entities.ExpirationUnitYear, Value: 17},
Name: in.CredentialName,
UserName: in.RegistryUsername,
})
if err != nil {
return nil, err
}

token, err := g.d.GetToken(regctx, in.RegistryUsername)
if err != nil {
return nil, err
}

dockerConfigJson, err := json.Marshal(map[string]any{
"auths": map[string]any{
g.ev.RegistryHost: map[string]any{
"auth": base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", creds.UserName, token))),
"auth": base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", creds.UserName, creds.TokenKey))),
},
},
})
Expand Down
1 change: 1 addition & 0 deletions apps/container-registry/internal/domain/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Domain interface {
ListCredentials(ctx RegistryContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.Credential], error)
CreateCredential(ctx RegistryContext, credential entities.Credential) (*entities.Credential, error)
DeleteCredential(ctx RegistryContext, userName string) error
CreateAdminCredential(ctx RegistryContext, credential entities.Credential) (*entities.Credential, error)

GetToken(ctx RegistryContext, username string) (string, error)
GetTokenKey(ctx context.Context, username string, accountname string) (string, error)
Expand Down
14 changes: 14 additions & 0 deletions apps/container-registry/internal/domain/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,17 @@ func (d *Impl) DeleteCredential(ctx RegistryContext, userName string) error {

return d.cacheClient.Drop(ctx, userName+"::"+ctx.AccountName)
}

func (d *Impl) CreateAdminCredential(ctx RegistryContext, credential entities.Credential) (*entities.Credential, error) {
i, err := admin.GetExpirationTime(fmt.Sprintf("%d%s", credential.Expiration.Value, credential.Expiration.Unit))
if err != nil {
return nil, errors.NewE(err)
}
token, err := admin.GenerateToken(KL_ADMIN, credential.AccountName, string(credential.Access), i, d.envs.RegistrySecretKey+credential.AccountName)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚨 issue (security): Hard-coded secret detected in the concatenation of d.envs.RegistrySecretKey with credential.AccountName. This approach can potentially expose sensitive information. Consider securely managing secrets, for example, through a secrets manager.


return &entities.Credential{
UserName: KL_ADMIN,
TokenKey: token,
}, nil

}
2 changes: 1 addition & 1 deletion apps/websocket-server/internal/domain/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (d *domain) handleLogsMsg(ctx types.Context, logsSubs *logs.LogsSubsMap, ms
utils.WriteInfo(ctx, "[logs] subscription cancelled for ", msg.Id, types.ForLogs)
} else {
ctx.Mutex.Unlock()
utils.WriteError(ctx, fmt.Errorf("[logs] no subscription found for account: %s, cluster: %s, trackingId: %s",
utils.WriteWarn(ctx, fmt.Errorf("[logs] no subscription found for account: %s, cluster: %s, trackingId: %s",
msg.Spec.Account, msg.Spec.Cluster, msg.Spec.TrackingId), msg.Id, types.ForLogs)
}

Expand Down
11 changes: 6 additions & 5 deletions apps/websocket-server/internal/domain/logs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ const (
)

type MsgData struct {
Account string `json:"account"`
Cluster string `json:"cluster"`
TrackingId string `json:"trackingId"`
Since *string `json:"since,omitempty"`
Account string `json:"account"`
Cluster string `json:"cluster"`
TrackingId string `json:"trackingId"`
Since *string `json:"since,omitempty"`
RecordVersion int `json:"recordVersion"`
}

type Message struct {
Expand Down Expand Up @@ -100,5 +101,5 @@ func ParseSince(since *string) (*time.Time, error) {
}

func LogSubsId(md MsgData, logStreamName string) string {
return fmt.Sprintf("%s.%s.%s.%s.>", logStreamName, md.Account, md.Cluster, md.TrackingId)
return fmt.Sprintf("%s.%s.%s.%s.%d.>", logStreamName, md.Account, md.Cluster, md.TrackingId, md.RecordVersion)
}
1 change: 1 addition & 0 deletions apps/websocket-server/internal/domain/types/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
MessageTypeError MessageType = "error"
MessageTypeResponse MessageType = "response"
MessageTypeInfo MessageType = "info"
MessageTypeWarning MessageType = "warning"
)

type Response[T any] struct {
Expand Down
11 changes: 11 additions & 0 deletions apps/websocket-server/internal/domain/utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ func WriteError(ctx types.Context, err error, id string, For types.For) {
}
}

func WriteWarn(ctx types.Context, err error, id string, For types.For) {
if err := ctx.WriteJSON(types.Response[any]{
Type: types.MessageTypeWarning,
Message: err.Error(),
For: For,
Id: id,
}); err != nil {
ctx.Logger.Warnf("websocket write: %w", err)
}
}

func WriteInfo(ctx types.Context, msg string, id string, For types.For) {
if err := ctx.WriteJSON(types.Response[any]{
Type: types.MessageTypeInfo,
Expand Down