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

Check for elevated permissions with automatic login #482

Merged
merged 50 commits into from
Sep 24, 2024

Conversation

gord5500
Copy link
Contributor

Why

The --experimental-bypass-browser-security flag is only useful when running as admin.

I'm not sure though if we would prefer to not completely kill the process as is happening here or just skip over the automatic login area. I lean to killing it so people don't get use to having this flag included regularly

Ticket

VUL-453

@@ -21,8 +23,28 @@
// allow no-sandbox argument for chromium to for passwordless auth with elevated permissions
var bypassBrowserSecurityOption = new Option<bool>(
name: "--experimental-bypass-browser-security",
getDefaultValue: () => false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The validator wasn't getting called without this if the flag wasn't included

Copy link
Member

Choose a reason for hiding this comment

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

wat

@@ -282,3 +304,8 @@
} )
.Build()
.InvokeAsync( args );

internal static partial class NativeMethods {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Top Level Statement L here?

Copy link
Member

Choose a reason for hiding this comment

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

I'd rather we wrap this along with the IsWindows, IsLinux, IsMacOS logic all in a separate file & class.

Copy link
Member

Choose a reason for hiding this comment

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

There's a lot happening in Program.cs already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

@gord5500 gord5500 marked this pull request as ready for review September 24, 2024 13:40
@gord5500 gord5500 requested a review from a team as a code owner September 24, 2024 13:40
@gord5500 gord5500 requested review from cfbao, boarnoah, scowing, jharoutuniand2l and AnimalXing and removed request for a team September 24, 2024 13:40
Comment on lines 309 to 310
[LibraryImport( "libc", EntryPoint = "geteuid" )]
public static partial uint GetPosixEuid();
Copy link
Member

Choose a reason for hiding this comment

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

Do you know if this works on Alpine with musl, AFAICS the musl implementation of libc, is called libc as far as imports in C etc... are concerned.

So this might work?

Copy link
Member

Choose a reason for hiding this comment

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

our existing libc calls work in alpine

""";
} else if( !isElevated && bypass ) {
result.ErrorMessage
= "BMX is not running with elevated permissions, so --experimental-bypass-browser-security must be set to false";
Copy link
Member

@boarnoah boarnoah Sep 24, 2024

Choose a reason for hiding this comment

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

nit: Isn't it better to say, something along the lines of: don't provide -experimental-bypass-browser-security

Copy link
Member

Choose a reason for hiding this comment

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

I'd say this is more than a nit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I'll reword

Comment on lines 39 to 40
Running BMX with elevated permissions is only allowed with the '--experimental-bypass-browser-security' flag.
Only include this if you aren't concerned with the security of the host for your Okta organization.
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would really like it if we could articulate that:

  1. Using BMX to do AWS stuff is perfectly fine while elevated
  2. You only need this flag when you want to do the equivalent of bmx login as admin
    a. Right call in most situations is to, run bmx login on your computer once a day without elevated privs
    b. If you insist in running BMX with elevated privs as the first thing of the day, that is when you need the flag.

Not sure how to fit all that in one sentence :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay so this checking for permission logic should go in the okta authenticator class then

Copy link
Member

Choose a reason for hiding this comment

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

There's also the consideration that... what if this flag is used with AWS credential process, and what if that may be triggered automatically sometimes elevated sometimes not?
This is a real concern for the LMS.

Copy link
Member

Choose a reason for hiding this comment

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

in other words, I'm not too sure that we should always fail BMX when this flag is present but the user isn't elevated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup I'll just move it to the okta authenticator and divert to password if it's not provided and they are admin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I moved it to the authenticator where if bmx is running as admin and no flag provided, we fall back to password. If not admin but flag provided, we set the flag to false so '--no-sandbox' doesn't get included

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that should also address the issue with wording you had Adipa since it's only on attempting to login now

@boarnoah
Copy link
Member

boarnoah commented Sep 24, 2024

I lean to killing it so people don't get use to having this flag included regularly

I would think we just silently not use the no-sandbox flag if we aren't escalated.

Set of things that lead us to have to use no-sandbox is kind of hard to convey to a user (you need to have a stale/close to stale okta session && you need to be trying to use bmx in that particular situation with escalated privs).

Regardless of what our users do poorly (IMO invoking tools that don't need escalation is such a thing) we should try to do the correct thing and try to not use no-sandbox whenever possible

CC @cfbao

EDIT: This also addresses Chenfeng's point about how credential process use of BMX means it could sometimes be escalated sometimes not

@cfbao
Copy link
Member

cfbao commented Sep 24, 2024

@boarnoah
yeah I agree with Adipa here.
BMX should never use --no-sandbox when not elevated, but forcing not using the flag when not elevated onto our user might be detrimental to UX.

Base automatically changed from add_passwordless to main September 24, 2024 15:27
cfbao
cfbao previously approved these changes Sep 24, 2024
bool hasElevatedPermissions = UserPrivileges.HasElevatedPermissions();
if( hasElevatedPermissions && !bypassBrowserSecurity ) {
consoleWriter.WriteWarning( $"""
BMX is being run with elevated privileges and is unable to automatically sign in to Okta.
Copy link
Member

Choose a reason for hiding this comment

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

Not in scope, but - some warnings messages are prefixed with "WARNING:" while others are not.
Would be nice to be consistent on this.
I lean towards no prefix, because we already use a different colour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yea you're right. I started with including the prefix since they were in the bmx config provider class but have been inconsistent. I see we use WriteWarning in other places though without it. I think I'll remove the prefix for this class

Comment on lines 154 to 155
If you have to run BMX with elevated privileges, and aren't concerned with the security of {orgUrl.Host},
consider running the command again with the '--experimental-bypass-browser-security' flag.
Copy link
Member

Choose a reason for hiding this comment

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

Nit:
When this happens, user might just enter their Okta password and move on, so this message is just an "FYI for next time", and they won't want to run this same command again right now even if they have to run BMX elevated and aren't concerned with the security of the Okta site.

Maybe a better message should say "consider using this flag" instead of "consider running the command again".

Another thing that bugs me and it concerns other related warning messages too - if a user can't use DSSO at all, either because their Okta org doesn't support it, or their computer or network condition isn't right, then ideally BMX shouldn't show any DSSO related warning messages at all. I don't think the current implementation does this.
No rush to fix this right now, but I'd like us to do something about this before releasing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think the current implementation does this.
Yea if there was no DSSO implementation for an org, they would end up always seeing some warning messages about it

I think readding the passwordless flag could solved this where it is just defaulted to true.

Copy link
Member

Choose a reason for hiding this comment

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

more like... --disable-passwordless that's default false.
or another flag/config name.
We should probably still rephrase some messages though.
later

@gord5500 gord5500 requested a review from boarnoah September 24, 2024 18:57
@gord5500 gord5500 merged commit 0401ee8 into main Sep 24, 2024
9 checks passed
@gord5500 gord5500 deleted the check_for_elevated_permission branch September 24, 2024 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants