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

Username sanitization #90

Merged
merged 2 commits into from Jun 17, 2022
Merged

Username sanitization #90

merged 2 commits into from Jun 17, 2022

Conversation

Szubie
Copy link
Collaborator

@Szubie Szubie commented Jun 16, 2022

bravetools uses the current username for:

  • Multipass VM name
  • LXD profile name
  • LXD storage pool name
  • LXD network bridge name

However, there are various rules regarding valid names for the above. In particular, multipass VM names and LXD network bridge names are most likely to cause issues.

  • LXD network bridge names are limited to 15 characters maximum
  • Multipass VM names are generally restricted to most alpha-numeric characters. A hyphen is allowed, but only in some cases (for example leading/trailing hyphen is not).

This pull request attempts to sanitize usernames so that they are valid for all the above uses. It is purposefully overly-cautious by stripping any non alpha-numeric charcaters to avoid dealing with those edge cases (for now). The username is actually restricted to 12 characters maximum, since "br0" is appended to the name to create the network bridge name.

Problems

This approach of attempting to clean usernames has some issues - after truncating or removing characters from usernames the username may no longer be a unique identifier. However, at least this change would at least let users who otherwise would not be able to use bravetools with their current username use the program.

…ere appropriate. This enables changing the implementation in the future.
platform/helpers.go Outdated Show resolved Hide resolved
@idroz idroz merged commit bc7d97b into bravetools:master Jun 17, 2022
@Szubie Szubie deleted the username-clean branch June 17, 2022 14:49
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.

None yet

2 participants