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

Keystone connector #1374

Merged
merged 4 commits into from
Jan 11, 2019
Merged

Keystone connector #1374

merged 4 commits into from
Jan 11, 2019

Conversation

kbalka
Copy link
Contributor

@kbalka kbalka commented Dec 14, 2018

PR contains connector for openstack keystone.

Features:

  • access tokens
  • refresh tokens
  • groups

Requirements:

  • access to openstack keystone instance
  • keystone administrative account credentials

Enabling keystone connector specific tests:

  • make sure docker is running
  • export DEX_TEST_KEYSTONE=1
  • make tests

Copy link

@soggiest soggiest left a comment

Choose a reason for hiding this comment

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

There looks to be incorrect tabbing in keystone.go and keystone_test.go. Please make sure the tab formatting is consistent, otherwise it is difficult to read the code.

logrus is imported but not used. Please change the fmt.Printf lines to use logrus to ensure consistency with the rest of Dex.

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

💯 🎈 🎉 Thank you for working on this 👍

(I'm assuming @knangia is on board with this. 👋)

A round of comments inline; adding to what @soggiest already raised.

A general point -- the way this connector interacts with docker seems new compared to the other test suites. It's dragging in new dependencies (and these aren't vendored, so tests fail). I wonder if we could rather add a docker run -d call to .travis.yml, like we do for etcd? This would let us avoid managing the keystone container from TestMain. (Furthermore, we could then simplify the tests a little, taking in DEX_KEYSTONE_URL and DEX_KEYSTONE_ADMIN_URL, or something like that, and calling t.Skip() if they're not set.)

connector/keystone/keystone.go Outdated Show resolved Hide resolved
connector/keystone/keystone.go Outdated Show resolved Hide resolved
connector/keystone/keystone.go Outdated Show resolved Hide resolved
connector/keystone/keystone.go Outdated Show resolved Hide resolved
connector/keystone/types.go Outdated Show resolved Hide resolved
connector/keystone/types.go Outdated Show resolved Hide resolved
examples/config-keystone.yaml Outdated Show resolved Hide resolved
connector/keystone/keystone_test.go Outdated Show resolved Hide resolved
connector/keystone/keystone_test.go Outdated Show resolved Hide resolved
@kbalka
Copy link
Contributor Author

kbalka commented Dec 17, 2018

Hi @srenatus, @soggiest, thanks for fast review. We will provide bunch of updates soon. To my best knowledge, @knangia is the loop.

Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

Thanks for taking on the previous batch of comments. I gave this another thorough read, please bear with me on the changes.

😃 I like how this is taking shape, and it'll be a nice addition. 🎉

I'm also curious about your use case. How do you plan to use dex-with-keystone? Which applications will likely leverage your openstack cluster's authentication? 😃

.travis.yml Outdated

install:
- sudo -E apt-get install -y --force-yes slapd time ldap-utils
- sudo /etc/init.d/slapd stop
- docker run -d --net=host gcr.io/etcd-development/etcd:v3.2.9

- docker run -d -p 0.0.0.0:5000:5000 -p 0.0.0.0:35357:35357 openio/openstack-keystone
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ I really don't know, so, this is not a leading question: What's the advantage of --net=host vs -p 0.0.0.0:5000:5000?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question :-) For me, the advantage here is only readability - you can see which ports are exposed and compare it with exported variables DEX_KEYSTONE*.

connector/keystone/keystone.go Outdated Show resolved Hide resolved
connector/keystone/keystone.go Outdated Show resolved Hide resolved
connector/keystone/keystone.go Outdated Show resolved Hide resolved
connector/keystone/keystone.go Outdated Show resolved Hide resolved
Methods []string `json:"methods"`
ExpiresAt string `json:"expires_at"`
User userKeystone `json:"user"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like some of these are not used? (Like the IssuedAt and ExpiresAt fields, but maybe more) -- Can we remove them or add a comment?

Also, do we need to care about the ExpiresAt for this connector's functionality? (I can't oversee that right now 😅 )

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 we don't need to care about ExpiresAt - because we are using token immediately after it's obtained. Keystone tokens are quite short living (I think by default 1h). Keeping it in identity.ConnectorData and using for Refresh would limit liveness of dex refresh token by expiration of keystone user token. That's why we require keystone admin account credentials. Admin should have access to other's users and their groups. When we check refresh token, the admin account gets fresh token from keystone and verifies user existence and groups. I hope that it makes some sense :-)

connector/keystone/keystone_test.go Outdated Show resolved Hide resolved
.travis.yml Outdated Show resolved Hide resolved
.travis.yml Outdated Show resolved Hide resolved
connector/keystone/keystone.go Outdated Show resolved Hide resolved
@srenatus
Copy link
Contributor

🎗 Note to self: let's squash these before merging.

@srenatus
Copy link
Contributor

Not right now, though! I appreciate the separate commits a lot for review 👍

@joannanosek
Copy link
Contributor

Hi @srenatus! Sorry for torpedoing with the commits 😅 And thank you for valuable feedback!

@kbalka
Copy link
Contributor Author

kbalka commented Dec 19, 2018

the application which can possibly leverage openstack cluster authentication is https://github.com/IntelAI/inference-model-manager :-)

func (p *keystoneConnector) Refresh(
ctx context.Context, s connector.Scopes, identity connector.Identity) (connector.Identity, error) {

token, err := p.getAdminToken(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this token be cached?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can add caching token across sessions if needed, but my opinion is that at this moment we should keep the code simple. Is it ok for you ?

func (p *keystoneConnector) Close() error { return nil }

func (p *keystoneConnector) Login(ctx context.Context, s connector.Scopes, username, password string) (
identity connector.Identity, validPassword bool, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: keep these arguments on one line

"github.com/sirupsen/logrus"
)

type keystoneConnector struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

already in the keystone package, so this can just be called "connector"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After moving this struct to keystone.go, name connector clashes with import "github.com/dexidp/dex/connector" , but I'm open to suggestions how to rename it

Copy link
Contributor

Choose a reason for hiding this comment

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

How about conn or plain c? Currently, other connectors use a similar name to what's introduced here (e.g. microsoftConnector), but I do agree that shorter is nicer, the context is clear here.

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, it makes sense. I've changed to conn.

Copy link
Contributor

@ericchiang ericchiang left a comment

Choose a reason for hiding this comment

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

Lots of little comments but thanks for the tests. Overall this looks like something we should merge.

Whenever you use a keystone endpoint, please add a comment including a link to the upstream docs for that endpoint. It helps others maintain and review :)

@kbalka
Copy link
Contributor Author

kbalka commented Dec 21, 2018

Hi @ericchiang, thanks for a thorough review. I'd addressed most of the issues. Please check if it looks better now. Regarding use of openio/openstack-keystone:latest image, I've asked the maintainer to add specific version tag, waiting for response. But, the most important, merry 🎄 and 🎅 to you together with @joannanosek @srenatus and @soggiest !

@soggiest
Copy link

soggiest commented Dec 21, 2018 via email

@ericchiang
Copy link
Contributor

FYI, I'm on vacation and won't be able to look at this until late next week. I promise I'm not just procrastinating :)

@srenatus srenatus mentioned this pull request Jan 9, 2019
Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

LGTM. (⏳ waiting for @ericchiang's approval, too.)

@srenatus
Copy link
Contributor

OK I'd really like to get a release out soon. Looking at the reviews, I think this is good to go.

Follow-up work can happen in another PR, this is mergeable. (The only thing I see as a potential improvement is caching the admin token. I'll create an issue for that when this is merged.)

@kbalka would you mind squashing those commits? Let's do it in a way that preserves @knangia's and @joannanosek's contributions -- either by adding a Co-authored-by: annotation, or by squashing commits per-author. 😃

@kbalka kbalka force-pushed the keystone-connector branch from a45dbaa to 88473bc Compare January 11, 2019 12:24
@kbalka
Copy link
Contributor Author

kbalka commented Jan 11, 2019

Hi @srenatus. Thanks for the approval !!! I've squashed the commits into number of 4, added authors and force-pushed the branch on my fork. The code seems to be ready for merge. The only strange thing I can observe that there is a "tail" of 8 commits in the PR which are already on the master. They will probably disappear after merge, but I'm not sure. I can fix the PR if needed.

@srenatus
Copy link
Contributor

srenatus commented Jan 11, 2019 via email

@kbalka kbalka force-pushed the keystone-connector branch from 88473bc to e8ba848 Compare January 11, 2019 14:16
@kbalka
Copy link
Contributor Author

kbalka commented Jan 11, 2019

@srenatus I've rebased to the master. looks like we are ready to hit the button :)

@srenatus
Copy link
Contributor

@kbalka Thank you so much! 🎉

@ericchiang sorry I didn't wait for your "👍" after all. Feel free to assign me anything that's left 😉

@srenatus srenatus merged commit f1581ff into dexidp:master Jan 11, 2019
mmrath pushed a commit to mmrath/dex that referenced this pull request Sep 2, 2019
PR contains connector for openstack keystone.

Features:

    access tokens
    refresh tokens
    groups

Requirements:

    access to openstack keystone instance
    keystone administrative account credentials

Enabling keystone connector specific tests:

    make sure docker is running
    export DEX_TEST_KEYSTONE=1
    make tests
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.

6 participants