Skip to content

Commit

Permalink
feat(secutiry): empty access keys
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Oct 8, 2024
1 parent 1c52b81 commit d83ecee
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
22 changes: 21 additions & 1 deletion db/AccessKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type AccessKey struct {
// UserID is an ID of user which owns the access key.
UserID *int `db:"user_id" json:"-" backup:"-"`

Empty bool `db:"-" json:"empty"`
Empty bool `db:"-" json:"empty,omitempty"`
}

type LoginPassword struct {
Expand Down Expand Up @@ -178,13 +178,33 @@ func (key *AccessKey) SerializeSecret() error {

switch key.Type {
case AccessKeyString:
if key.String == "" {
key.Secret = nil
return nil
}
plaintext = []byte(key.String)
case AccessKeySSH:
if key.SshKey.PrivateKey == "" {
if key.SshKey.Login != "" || key.SshKey.Passphrase != "" {
return fmt.Errorf("invalid ssh key")
}
key.Secret = nil
return nil
}

plaintext, err = json.Marshal(key.SshKey)
if err != nil {
return err
}
case AccessKeyLoginPassword:
if key.LoginPassword.Password == "" {
if key.LoginPassword.Login != "" {
return fmt.Errorf("invalid password key")
}
key.Secret = nil
return nil
}

plaintext, err = json.Marshal(key.LoginPassword)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions db/sql/access_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func (d *SqlDb) GetAccessKeys(projectID int, params db.RetrieveQueryParams) (key

_, err = d.selectAll(&keys, query, args...)

for i := range keys {
if keys[i].Secret == nil {
keys[i].Empty = true
}
}

return
}

Expand Down
10 changes: 10 additions & 0 deletions web/src/views/project/Keys.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
class="mt-4"
:items-per-page="Number.MAX_VALUE"
>
<template v-slot:item.name="{ item }">
{{ item.name }}
<v-chip
color="error"
v-if="item.empty && item.type !== 'none'"
small
style="font-weight: bold;"
class="ml-2"
>Empty</v-chip>
</template>
<template v-slot:item.type="{ item }">
<code>{{ item.type }}</code>
</template>
Expand Down

0 comments on commit d83ecee

Please sign in to comment.