Better compatibility with Okta as IDP - Custom scopes and escaped groups in tables#120
Better compatibility with Okta as IDP - Custom scopes and escaped groups in tables#120yonatan-sevenai wants to merge 8 commits into
Conversation
|
Thanks for this, I won't get a chance to review until next week |
|
Just stumbled upon this while wondering about the scopes requested for the custom provider. Currently, opkssh requests the Please don't make any changes to this PR based on my comment until @EthanHeilman has had the time to look at it as well. |
|
I think the ideal way would be to refactor how configuration of providers is done and externalize this to a config file. This way, the login command can take a shortcut to an existing provider, and the web-ui can be rendered based on your existing providers. Not sure I'll have time to whip the above together, so this is more in lines of wishful thinking at this point. |
|
As a stop gap, we might say that the only scope being requested is "openid" and, when scopes are provided, the user must specify if they want profile, email, groups, etc... |
|
I'll try to join. |
I like the intention behind this of protecting people from themselves, in this case I don't think we should append. If scopes are specified, we should only use those scopes even tho someone might not specify the openid scope and then discover it doesn't work. It is better for them to realize they need the openid scope, then to hide this fact from them. Additionally there is always going to be some weird provider that uses weird scopes and breaks if you specify As far as I can tell I believe specifying scopes was added in another separate PR: // ProviderConfig is the representation of the provider config:
// {alias},{provider_url},{client_id},{client_secret},{scopes}
// client secret is optional, as well as scopes, if not provided, the default for secret is an empty string, for scopes is "openid profile email"
type ProviderConfig struct {
Alias string
Issuer string
ClientID string
ClientSecret string
Scopes []string
} |
EthanHeilman
left a comment
There was a problem hiding this comment.
Fix the merge conflict with the prior scopes change and then add a unit test. Other than that this looks good to merge
|
I removed the scoped portion of my PR as it was already covered in https://github.com/openpubkey/opkssh/blame/97b81e96004d3a6931207736ba151e8374ba4d35/commands/login.go#L470-L479. |
|
@EthanHeilman - Can you re-review and merge? This will allow support for group names with spaces in the tables. |
EthanHeilman
left a comment
There was a problem hiding this comment.
Thanks for this PR. It looks really good. I appreciate the work you put in and I'm eager to merge this.
I want to make sure this won't break any existing files:
- Add an end to end test from an policy file with escaped spaces to a policy enforcer check.
- Add a provider file unit test
I am slightly worried that someone that has a \ in their provider config this change would make it no longer match (see unit test I added below).
For instance someone had a provider line like
https:://issuer.example.com asdfsdfsd\bdfsdfsd 24h
which currently would match for the clientID asdfsdfsd\bdfsdfsd but after this change would no longer match. This seems unlikely but I want to extra cautious about anything that could lock someone out.
I edited the PR description since it was out of date.
|
Is there a reason we are rolling our own here instead of using something like shlex? |
|
@markafarrell That is an excellent point. @yonatan-sevenai is there any downside to using @shlex here? It gets us quoting as well which is another requested feature |
|
@EthanHeilman, @markafarrell - Thanks for this note. I think we should stick with the current implementation for the following reasons
If anything, as part of the YAML user config, we can start moving all configurations to YAMLs which will be more readable than current table based approach. |
|
@yonatan-sevenai I want to think through this case by case, please excuse my pedantry: Where unescaped spaces might be a problem Specify a provider on the client side
Specifying a provider on the server sideIn Specifying policy
Neither the principal nor the issuer will contain spaces, so the only issue is the requirement part of the policy or Wouldn't @markafarrell
The PR needs to address the disappearing escapes before this can be merged. That said, I'm leaning toward using shlex here. We could just quote all policy requirements that have a space. |
|
To assist with the discussion this is what it would look like using : |
|
@EthanHeilman - Regarding your comment - the CLI side is okay as you listed. In fact, we don't need to do anything as the shell will correctly escape shell for us. The problem is purely for the on-disk table format. The current implementation breaks with the table on-disk format as it uses spaces to separate fields. Another thing to remember is that we need to both read and write to tables in a consistent way. Therefore, using As for |
|
@yonatan-sevenai Your backwards compatibility concern is that someone might have a line like: which we would unescape to |
|
Is it worth raise a PR to document the current behaviour in |
|
@EthanHeilman - The example of an escape or quote within a group name is the scenario I had in mind. There's a work-around, in introducing a version line to the table format, and reverting to the existing behavior if no such version line appears consider starting each table with the line |
|
We're moving to #158 as the base implementation. |
Summary:
This pull request introduces enhancements to the login command and policy file parsing functionalities.
It includes support for custom scopes in the provider argument handling in the login command andadds new utility functions allowing groups with spaces in their names (such as "group name" to be valid in/etc/opk/providers)While this was designed with Okta as the test-case for IDPs, nothing in this code is specific to Okta.
Two new capabilities are supported
./opkssh add user "oidc:groups:group with space" https://some.sso.domain- This will add the group "group with space" and allow it to verify in oidc:groups verifications../opkssh login --provider=https://subdomain.okta.com,client_id,,groups- This will login to the application in Okta adding the "groups" scopes to have okta include group informationDetailed Description:
Changes in
commands/login.go:Modified the validation logic for the provider argument to support an additional format:<issuer>,<client_id>,<client_secret>,<additional_scopes>.Updated the error message to reflect the new expected format.Introduced logic to handle additional scopes by appending them to theopts.Scopesif provided for custom providers.Changes in
policy/files/table.go:fieldsEscaped: A function to split strings on whitespace boundaries while preserving escaped spaces and backslashes.writeEscaped: A function to join fields into a single string, escaping spaces and backslashes to ensure correct parsing.NewTableto usefieldsEscapedfor parsing rows, allowing for more flexible handling of spaces and backslashes in policy files.ToStringto usewriteEscapedfor converting rows back to strings, ensuring that spaces and backslashes are correctly escaped.Impact:
Login Command: Users can now specify additional scopes in the provider argument, supporting OIDC providers who don't include group information by default.