feat: cleanup disclaimer and command to add users

This commit is contained in:
Eli Bosley
2025-01-23 12:02:04 -05:00
parent 0da77d7119
commit 3867dfacb2
3 changed files with 27 additions and 14 deletions

View File

@@ -28,13 +28,21 @@ export class AddSSOUserCommand extends CommandRunner {
} }
async run(_input: string[], options: AddSSOUserCommandOptions): Promise<void> { async run(_input: string[], options: AddSSOUserCommandOptions): Promise<void> {
options = await this.inquirerService.prompt(AddSSOUserQuestionSet.name, options); try {
options = await this.inquirerService.prompt(AddSSOUserQuestionSet.name, options);
if (options.disclaimer === 'y') { if (options.disclaimer === 'y' && options.username) {
await store.dispatch(loadConfigFile()); await store.dispatch(loadConfigFile());
store.dispatch(addSsoUser(options.username)); store.dispatch(addSsoUser(options.username));
writeConfigSync('flash'); writeConfigSync('flash');
this.logger.info('User added ' + options.username); this.logger.info('User added ' + options.username);
}
} catch (e: unknown) {
if (e instanceof Error) {
this.logger.error('Error adding user: ' + e.message);
} else {
this.logger.error('Error adding user');
}
} }
} }

View File

@@ -1,4 +1,5 @@
import { Question, QuestionSet } from 'nest-commander'; import { Question, QuestionSet } from 'nest-commander';
import { v4 as uuidv4 } from 'uuid';
@@ -9,7 +10,12 @@ export class AddSSOUserQuestionSet {
static name = 'add-user'; static name = 'add-user';
@Question({ @Question({
message: 'Are you sure you wish to add a user for SSO - this will enable single sign on in Unraid and has certain security implications? (y/n)', message: `Enabling Single Sign-On (SSO) will simplify authentication by centralizing access to your Unraid server. However, this comes with certain security considerations: if your SSO account is compromised, unauthorized access to your server could occur.
Please note: your existing username and password will continue to work alongside SSO.
Are you sure you want to proceed with adding a user for SSO? (y/n)
`,
name: 'disclaimer', name: 'disclaimer',
validate(input) { validate(input) {
if (!input) { if (!input) {
@@ -29,14 +35,17 @@ export class AddSSOUserQuestionSet {
} }
@Question({ @Question({
message: 'What is the cognito username (NOT YOUR UNRAID USERNAME)? Find it in your Unraid Account at https://account.unraid.net', message:
"What is your Unique Unraid Account ID? Find it in your Unraid Account at https://account.unraid.net/settings\n",
name: 'username', name: 'username',
validate(input) { validate(input) {
if (!input) { if (!input) {
return 'Username is required'; return 'Username is required';
} }
if (!/^[a-zA-Z0-9-]+$/.test(input)) { const randomUUID = uuidv4();
return 'Username must be alphanumeric and can include dashes.';
if (!/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(input)) {
return `Username must be in the format of a UUID (e.g., ${randomUUID}).`;
} }
return true; return true;
}, },

View File

@@ -759,10 +759,6 @@ if ([[ -n "${email}" && (-z "${apikey}" || "${#apikey}" -ne "64") ]]); then
}' "${CFG}">"${CFG}-new" && mv "${CFG}-new" "${CFG}" CFG_CLEANED=1 }' "${CFG}">"${CFG}-new" && mv "${CFG}-new" "${CFG}" CFG_CLEANED=1
echo "⚠️ Automatically signed out of Unraid.net" echo "⚠️ Automatically signed out of Unraid.net"
fi fi
# if there wasn't an email or the CFG was cleaned
if [[ -z "${email}" ]] || [[ CFG_CLEANED -eq 1 ]]; then
echo "✨ Sign In to Unraid.net to use Unraid Connect ✨"
fi
# configure flash backup to stop when the system starts shutting down # configure flash backup to stop when the system starts shutting down
[[ ! -d /etc/rc.d/rc6.d ]] && mkdir /etc/rc.d/rc6.d [[ ! -d /etc/rc.d/rc6.d ]] && mkdir /etc/rc.d/rc6.d