Skip to content
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

feat: manage ssh keys for accounts #187

Merged
merged 103 commits into from
Dec 9, 2024

Conversation

polillomm
Copy link
Member

No description provided.

…turn encoded content instead default content
Copy link
Member Author

@polillomm polillomm left a comment

Choose a reason for hiding this comment

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

Dev review ok.

contentBytes := []byte(content.String())
publicKey, _, _, _, err := ssh.ParseAuthorizedKey(contentBytes)
if err != nil {
return secureAccessPublicKey, errors.New("SecureAccessPublicKeyParseError")
Copy link
Contributor

Choose a reason for hiding this comment

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

You gotta have an unit test on this situation since there is some logic here that may break. Does the FingerprintSHA256 works for both RSA and ED25519?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it validates both types of keys. I tested both!

if err != nil {
return errors.New("AccountNotFound")
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't usually return the infra error directly to the user. I guess you forgot the slog.Error here? The previous "AccountNotFound" was the correct to return to the user.

readRequestDto := dto.ReadSecureAccessPublicKeysRequest{
SecureAccessPublicKeyId: &deleteDto.Id,
}
keyToDelete, err := accountQueryRepo.ReadFirstSecureAccessPublicKey(
Copy link
Contributor

Choose a reason for hiding this comment

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

publicKeyEntity

if err != nil {
return errors.New("AccountNotFound")
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here. Please check all the cases you replaced NotFound with the infra err. It's not right.

voHelper "github.com/goinfinite/os/src/domain/valueObject/helper"
)

const SecureAccessPublicKeyContentRegex string = `^(?:ssh-(?:rsa|ed25519)) (?:[\w\/\+\=]+)(?: [\w@\-_]{6,32})?$`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this exported?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this regex validation and decided to validate it the same way we do with SslContent: there's no need to use a regex if we already have a parser to handle the validation, as it's done in the entity.

Comment on lines 116 to 121
htmx.ajax(
'DELETE',
`/api/v1/account/secure-access-public-key/${this.secureAccessPublicKey.id}/`,
{swap: 'none'},
);
this.$dispatch('delete:secure-access-public-key');
Copy link
Contributor

Choose a reason for hiding this comment

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

On Ez I started adding dispatch using a .then() on the htmx.ajax to make sure it only gets triggered when the request is successful. Little touch, but avoids future complains.

'/api/v1/account/' + this.account.id + '/',
{swap: 'none'},
);
htmx.ajax('DELETE', `/api/v1/account/`, {swap: 'none'});
this.$dispatch('delete:account');
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

templ SecureAccessPublicKeysList() {
@componentStructural.Alert(
componentStructural.AlertTypeInfo,
"The management of these public keys will only be possible if the OpenSSH service is installed. Otherwise, you won't be able to add or remove public keys, as they are used for SSH access.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, you can manage keys, they will just not have any meaning without OpenSSH. I think your description should tell people that. Don't you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, the route does not allow adding or removing keys as it performs a check to ensure the service is running. However, upon reflection, any modification to the authorized_keys file is irrelevant regardless of whether the service is running, which is entirely different from the case of databases, for example.

I removed this validation from the routes, now allowing requests to function normally. However, without the service, it won't serve any purpose. Additionally, I updated the alert content as well!

@@ -255,3 +319,92 @@ templ UpdateApiKeyModal() {
@UpdateApiKeyContent()
}
}

templ SecureAccessPublicKeysList() {
Copy link
Contributor

Choose a reason for hiding this comment

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

SecureAccessPublicKeysModalList

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't make much sense to use this name, considering this isn't the modal itself but its content, similar to how we handle forms, tabs, and other components. Moreover, this name suggests a list of modals rather than a modal containing a list.

@componentForm.InputField(componentForm.InputFieldDto{
Type: settingEntity.Value.GetType(),
Label: settingEntity.Name.String(),
BindModelValuePath: "phpConfigs.settings[" + strconv.FormatInt(int64(settingIndex), 10) + "].value",
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use strconv.Itoa here I think.

…nfra env that store user data base directory
…hat the file will be automatically recreated
Copy link
Member Author

@polillomm polillomm left a comment

Choose a reason for hiding this comment

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

Dev review ok.

voHelper "github.com/goinfinite/os/src/domain/valueObject/helper"
)

const SecureAccessPublicKeyNameRegex string = `^[\w@\-_]{6,32}$`
Copy link
Contributor

Choose a reason for hiding this comment

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

The key name may start with a - _ or @? That's weird. I think you should go with ^[A-Za-z0-9][\w@\-_]{5,32}$ instead.

@ntorga ntorga merged commit 86ba9bb into goinfinite:main Dec 9, 2024
@polillomm polillomm deleted the feat/manage-ssh-keys-for-accounts branch December 10, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants