mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-21 00:24:57 +02:00
feat(api): encrypt AWS creds (#37679)
## Description As mentioned in #37654 `AWSSecretAccessKey` are not encrypted and stored as is. ## Update Follow the existing `AuthToken` flow of setting the `Encrypted` fields, `Decrypting` them later and `Clearing` them at the end. Closes #37654 --------- Signed-off-by: Kausthubh J Rao <105716675+Exgene@users.noreply.github.com> Co-authored-by: Lauris B <lauris@nix.lv> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
This commit is contained in:
parent
2450127c56
commit
5c887d68ca
@ -137,6 +137,11 @@ func (task *Task) MigrateConfig() (*migration.MigrateOptions, error) {
|
|||||||
log.Error("Unable to decrypt AuthToken, maybe SECRET_KEY is wrong: %v", err)
|
log.Error("Unable to decrypt AuthToken, maybe SECRET_KEY is wrong: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if opts.AWSSecretAccessKeyEncrypted != "" {
|
||||||
|
if opts.AWSSecretAccessKey, err = secret.DecryptSecret(setting.SecretKey, opts.AWSSecretAccessKeyEncrypted); err != nil {
|
||||||
|
log.Error("Unable to decrypt AWSSecretAccessKey, maybe SECRET_KEY is wrong: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &opts, nil
|
return &opts, nil
|
||||||
}
|
}
|
||||||
@ -201,6 +206,8 @@ func FinishMigrateTask(ctx context.Context, task *Task) error {
|
|||||||
conf.AuthPasswordEncrypted = ""
|
conf.AuthPasswordEncrypted = ""
|
||||||
conf.AuthTokenEncrypted = ""
|
conf.AuthTokenEncrypted = ""
|
||||||
conf.CloneAddrEncrypted = ""
|
conf.CloneAddrEncrypted = ""
|
||||||
|
conf.AWSSecretAccessKey = ""
|
||||||
|
conf.AWSSecretAccessKeyEncrypted = ""
|
||||||
confBytes, err := json.Marshal(conf)
|
confBytes, err := json.Marshal(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@ -40,5 +40,7 @@ type MigrateOptions struct {
|
|||||||
MirrorInterval string `json:"mirror_interval"`
|
MirrorInterval string `json:"mirror_interval"`
|
||||||
|
|
||||||
AWSAccessKeyID string
|
AWSAccessKeyID string
|
||||||
AWSSecretAccessKey string
|
AWSSecretAccessKey string `json:",omitempty"`
|
||||||
|
|
||||||
|
AWSSecretAccessKeyEncrypted string `json:"aws_secret_access_key_encrypted,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,6 +85,11 @@ func CreateMigrateTask(ctx context.Context, doer, u *user_model.User, opts base.
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
opts.AuthToken = ""
|
opts.AuthToken = ""
|
||||||
|
opts.AWSSecretAccessKeyEncrypted, err = secret.EncryptSecret(setting.SecretKey, opts.AWSSecretAccessKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
opts.AWSSecretAccessKey = ""
|
||||||
bs, err := json.Marshal(&opts)
|
bs, err := json.Marshal(&opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user