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

hab cli api/depot authentication #708

Merged
merged 2 commits into from
Jun 10, 2016
Merged

hab cli api/depot authentication #708

merged 2 commits into from
Jun 10, 2016

Conversation

reset
Copy link
Collaborator

@reset reset commented Jun 10, 2016

We now honor the HAB_AUTH_TOKEN env variable and --auth/-z flag when calling CLI functions that require authentication. We currently only protect origin key upload and package upload.

This also contains an improvement to SessionSrv which will perform a session create if a session get is a cache miss. To accomplish this SessionSrv needed to be able to speak to GitHub's API so the oauth module has moved from the builder-api crate to the net crate

gif-keyboard-2294867843573839129

@thesentinels
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @metadave, @fnichol, @adamhjk, @smith and @seth to be potential reviewers

@@ -54,7 +54,7 @@ dependencies = [
"iron 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"persistent 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
Copy link
Contributor

Choose a reason for hiding this comment

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

We're not using the parts of serde that require nightly rust, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope! I don't think we actually even use serde, whatever crate is pulling this in just probably doesn't have/we didn't use the feature flag to disable serde

"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"protobuf 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Both rustc-serialize and serde is probably overkill.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just checked - Unfortunately I can't get rid of the Serde dependency here because the bodyparser doesn't expose a feature flag to disable Serde and it introduces it as a dependency

@adamhjk
Copy link
Contributor

adamhjk commented Jun 10, 2016

I haven't run or tested this code at all; but it all looks sane. :)

No nobody will need to ask:

gif-keyboard-18423081500114034805

}
Err(e @ hab_net::Error::JsonDecode(_)) => {
debug!("github user get, err={:?}", e);
let err = net::err(ErrCode::BAD_REMOTE_REPLY, "rg:auth:1");
Copy link
Contributor

Choose a reason for hiding this comment

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

is rg: the correct prefix here?

On SessionGet if the session is expired a new session will now be created

Signed-off-by: Jamie Winsor <[email protected]>
@bookshelfdave
Copy link
Contributor

so good.
gif-keyboard-15906873149773864063

0x00, 0x02, 0x00, 0x04, 0x12, 0x03, 0x0b, 0x02, 0x0a, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02,
0x00, 0x06, 0x12, 0x03, 0x0b, 0x0b, 0x13, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x01,
0x12, 0x03, 0x0b, 0x14, 0x1c, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x03, 0x12, 0x03,
0x0b, 0x1f, 0x20, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x01, 0x12, 0x03, 0x0c, 0x02, 0x1b,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo here, should read "0x0a, 0x0b, L0LH3XC0DE"

@fnichol
Copy link
Collaborator

fnichol commented Jun 10, 2016

@reset Wow, I'm impressed, sliding that into the CLI was far less effort than I thought. Glad to see that depot-client is doing all the heavy lifting (which frankly isn't tons).

One question came to mind: is it ever appropriate to serialize the bearer token to disk for repeated use over a time period? What I'm wondering is: could/should this be read from disk if we were to ask for a token in hab cli setup?

@fnichol
Copy link
Collaborator

fnichol commented Jun 10, 2016

I am merge 👍 on this stuff!

gif-keyboard-8610605194006386843

@reset
Copy link
Collaborator Author

reset commented Jun 10, 2016

@fnichol totally! If you'd like to have a part of setup where it displays:

## Generate auth token
We need you to generate an authentication token from GitHub to validate that you, are you.

1. Login to GitHub
1. Go to your personal access tokens: https://github.com/settings/tokens
1. Generate a new token
  a. Check the `user:email` box
1. Copy the newly generated personal access token

[press enter to continue]
GitHub personal access token: <enter token>
[press enter to continue]

We could then write this value into a settings file on disk at ~./hab/config.toml. After that you've just got to update the CLI to read from that file.

@fnichol
Copy link
Collaborator

fnichol commented Jun 10, 2016

@reset I could probably turn something around here. Wouldn't impact moving this through though.

@fnichol
Copy link
Collaborator

fnichol commented Jun 10, 2016

@reset Do we need to wait on merging (pending some other PR), or can I do the merge dance?

@reset
Copy link
Collaborator Author

reset commented Jun 10, 2016

@fnichol if you're going to build on top of this why don't you go ahead and merge it. I'll accept a review from Dave tomorrow on the merged PR and fix/add whatever he wants. Sound good?

@fnichol
Copy link
Collaborator

fnichol commented Jun 10, 2016

Works for me

gif-keyboard-11937980919000671279

@thesentinels r+

@thesentinels
Copy link
Contributor

📌 Commit a3416df has been approved by fnichol

@thesentinels
Copy link
Contributor

⌛ Testing commit a3416df with merge 4ddc698...

thesentinels pushed a commit that referenced this pull request Jun 10, 2016
Signed-off-by: Jamie Winsor <[email protected]>

Pull request: #708
Approved by: fnichol
thesentinels pushed a commit that referenced this pull request Jun 10, 2016
On SessionGet if the session is expired a new session will now be created

Signed-off-by: Jamie Winsor <[email protected]>

Pull request: #708
Approved by: fnichol
@thesentinels
Copy link
Contributor

☀️ Test successful - travis

@thesentinels thesentinels merged commit a3416df into master Jun 10, 2016
@fnichol fnichol deleted the cli-auth branch June 10, 2016 04:31
jtimberman pushed a commit that referenced this pull request Jun 12, 2016
Signed-off-by: Jamie Winsor <[email protected]>

Pull request: #708
Approved by: fnichol
jtimberman pushed a commit that referenced this pull request Jun 12, 2016
On SessionGet if the session is expired a new session will now be created

Signed-off-by: Jamie Winsor <[email protected]>

Pull request: #708
Approved by: fnichol
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.

5 participants