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

Allow Okta auth backend to specify TTL and max TTL values #2915

Merged
merged 3 commits into from
Jul 5, 2017

Conversation

wjam
Copy link
Contributor

@wjam wjam commented Jun 23, 2017

Allow Okta auth backend to have a TTL different to the system max TTL.

The TTL value is configurable per-backend rather than per-group as when logging in one user may match against multiple groups.

@jefferai jefferai added this to the 0.7.4 milestone Jun 29, 2017
@jefferai
Copy link
Member

jefferai commented Jul 1, 2017

Hi @wjam ,

Thanks for sending this in!

I'm happy with the feature being added, but I don't like the TTL/MaxTTL being returned from the login function. I'd much prefer that pathLogin/pathRenew read the configuration directly.

@wjam
Copy link
Contributor Author

wjam commented Jul 2, 2017

Changed implementation

@@ -26,6 +27,14 @@ func pathConfig(b *backend) *framework.Path {
Description: `The API endpoint to use. Useful if you
are using Okta development accounts.`,
},
"ttl": &framework.FieldSchema{
Type: framework.TypeString,
Copy link
Member

Choose a reason for hiding this comment

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

This should be TypeDurationSecond, same with max_ttl.

@@ -75,6 +84,8 @@ func (b *backend) pathConfigRead(
Data: map[string]interface{}{
"Org": cfg.Org,
Copy link
Member

Choose a reason for hiding this comment

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

Please use lowercase for these and match the input values, e.g. ttl and max_ttl. Please also change the existing values -- I know it would be an incompatible change but it's an uncommon endpoint that will be read mostly by humans. It's better for them to match the input.

@@ -118,6 +129,31 @@ func (b *backend) pathConfigWrite(
cfg.BaseURL = d.Get("base_url").(string)
}

var ttl time.Duration
ttlRaw, ok := d.GetOk("ttl")
Copy link
Member

Choose a reason for hiding this comment

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

Once you switch to TypeDurationSecond most of this goes away -- you are guaranteed to get a valid int out of a Get call. So a zero value can just mean "not set" and can be used directly.

}
}

cfg.TTL = ttl
Copy link
Member

Choose a reason for hiding this comment

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

this will then be ttl * time.Second.

return 0, 0, errors.New("Okta backend not configured")
}

ttl, maxTTL, err = b.SanitizeTTLStr(cfg.TTL.String(), cfg.MaxTTL.String())
Copy link
Member

Choose a reason for hiding this comment

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

This call is unnecessary, you're converting from a duration to a string back to a duration. LeaseExtend does bounds checking so you'll be fine as-is.

@wjam
Copy link
Contributor Author

wjam commented Jul 2, 2017

Pushed changes from code review.

The GitHub auth backend should probably be changed at some point to use TypeDurationSecond rather than TypeString

@jefferai
Copy link
Member

jefferai commented Jul 3, 2017

@wjam Yes, probably. Happy to take a PR from you that does that :-)

testAccUserGroups(t, username, "local_group,local_group2"),
testAccGroups(t, "local_group", "local_group_policy"),
testLoginWrite(t, username, password, "", []string{"local_group_policy"}),
testLoginWrite(t, username, password, "", defaultLeaseTTLVal.Nanoseconds(), []string{"local_group_policy"}),
Copy link
Member

Choose a reason for hiding this comment

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

Why are you using .Nanoseconds() everywhere? You can just compare the time.Duration values directly!

@jefferai
Copy link
Member

jefferai commented Jul 3, 2017

This is looking much better -- just a bit of cleanup on the tests and I think it's good to go!

@jefferai jefferai requested a review from calvn July 3, 2017 13:19
@wjam
Copy link
Contributor Author

wjam commented Jul 3, 2017

No idea why I was converting both durations to nanoseconds, I guess at some point they weren't both durations?

Pushed change to fix code review issue

@jefferai jefferai merged commit dc33aca into hashicorp:master Jul 5, 2017
@jefferai
Copy link
Member

jefferai commented Jul 5, 2017

Thanks!

@jefferai jefferai modified the milestones: 0.7.4, 0.8.0 Jul 24, 2017
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