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

Fixes metadata format for 'ssh-keys' key #455

Merged
merged 2 commits into from
Jun 7, 2019

Conversation

kgaikwad
Copy link
Contributor

Closes #454

@Temikus Temikus self-assigned this Apr 21, 2019
@codecov
Copy link

codecov bot commented Apr 21, 2019

Codecov Report

Merging #455 into master will decrease coverage by 22.06%.
The diff coverage is 20%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #455       +/-   ##
===========================================
- Coverage   88.86%   66.79%   -22.07%     
===========================================
  Files         339      249       -90     
  Lines        5629     4258     -1371     
===========================================
- Hits         5002     2844     -2158     
- Misses        627     1414      +787
Impacted Files Coverage Δ
lib/fog/compute/google/models/server.rb 30.84% <20%> (-43.78%) ⬇️
lib/fog/compute/google/models/servers.rb 20.75% <0%> (-75.48%) ⬇️
lib/fog/compute/google/models/addresses.rb 28.57% <0%> (-71.43%) ⬇️
lib/fog/compute/google/models/subnetworks.rb 30.43% <0%> (-69.57%) ⬇️
lib/fog/compute/google/models/forwarding_rules.rb 31.81% <0%> (-68.19%) ⬇️
lib/fog/compute/google/models/disks.rb 32% <0%> (-68%) ⬇️
lib/fog/compute/google/models/images.rb 24% <0%> (-66%) ⬇️
lib/fog/compute/google/models/target_pools.rb 29.16% <0%> (-62.5%) ⬇️
lib/fog/compute/google/models/target_instances.rb 29.16% <0%> (-62.5%) ⬇️
lib/fog/compute/google/requests/insert_server.rb 22.22% <0%> (-60%) ⬇️
... and 241 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 551ebb5...a8a26c1. Read the comment docs.

@kgaikwad
Copy link
Contributor Author

@Temikus,
I would like to know if any changes required from myside for this PR to get it merge?

@Temikus
Copy link
Member

Temikus commented May 19, 2019

@kgaikwad PTAL at my comments in #454

While this would make the keys work with your key format, it will most likely break it for others, as if someone just reads off a key generated by ssh-keygen it will now look like:

ssh-rsa AAAALONGKEY== user@host user

, which would be invalid.

If you want to proceed with this PR (for example some library/util gives you an ssh key without postfix) - you'll need to make the statement conditional. E.g. if the key doesn't have the username at the end, add it.

Makes sense?

@icco
Copy link
Member

icco commented May 27, 2019

As much as I hate adding new dependencies, we could use something like https://github.com/bensie/sshkey to parse incoming keys and add a comment if one was missing.

@Temikus
Copy link
Member

Temikus commented May 28, 2019

@icco Using a full-blown generator lib to parse keys would IMO be overkill. TBH I think just notifying of the correct format would suffice, as the problem is with the API accepting something that the console can’t parse.

Or am I missing something here?

@kgaikwad
Copy link
Contributor Author

I also agree with @Temikus.
Probably, I will make my statement conditional as you mentioned. I will add username at the end only if comment is absent.

Copy link

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

I believe it is worth a while to use proper parser for validating correct format of the key, or at least document the supported formats. That being said, we could just easily add the comment part only if missing...

@kgaikwad
Copy link
Contributor Author

kgaikwad commented May 31, 2019

I believe it is worth a while to use proper parser for validating correct format of the key, or at least document the supported formats. That being said, we could just easily add the comment part only if missing...

Thank you @ezr-ondrej for review.
Yeah, this is what we have discussed to add username only if comment is absent.
If everyone agree on adding a parser and raising an error for invalid format then I will be happy to add your suggested changes.

It would be good if we document those formats but in google document, these details are already present.

@icco
Copy link
Member

icco commented May 31, 2019 via email

@kgaikwad kgaikwad force-pushed the 454_ssh_keys_format_in_metadata branch from f2998e6 to a8a26c1 Compare May 31, 2019 14:22
@codecov
Copy link

codecov bot commented May 31, 2019

Codecov Report

Merging #455 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #455      +/-   ##
==========================================
+ Coverage   88.86%   88.86%   +<.01%     
==========================================
  Files         339      339              
  Lines        5629     5633       +4     
==========================================
+ Hits         5002     5006       +4     
  Misses        627      627
Impacted Files Coverage Δ
lib/fog/compute/google/models/server.rb 75.12% <100%> (+0.5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 551ebb5...261e959. Read the comment docs.

@kgaikwad
Copy link
Contributor Author

Updated PR! I will squash changes to single commit once ready for merge.

Though comment field is optional one, in document it clearly states that public-key should match format:ssh-rsa [KEY_VALUE] [USERNAME]
Here, I am still thinking that handling a condition to check comment presence should be sufficient.
Apart from this, I don't see anything else we required here.
Google is already doing a validation part then using parser, what we will achieve differently?

Please let me know if I am missing anything or are there any places where it is needed?

@ezr-ondrej
Copy link

I guess it is good enough. As the method is pretty small and straight forward, I guess we do not need to use external library to achieve the same thing.

Copy link
Member

@icco icco left a comment

Choose a reason for hiding this comment

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

One small change

@kgaikwad kgaikwad force-pushed the 454_ssh_keys_format_in_metadata branch from a8a26c1 to 261e959 Compare June 2, 2019 04:44
@kgaikwad
Copy link
Contributor Author

kgaikwad commented Jun 2, 2019

Thank you @ezr-ondrej and @icco! Updated PR as per suggested changes.

Copy link

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

👍 thanks @kgaikwad, LGTM

@ezr-ondrej
Copy link

What do you think @Temikus ?

@Temikus
Copy link
Member

Temikus commented Jun 7, 2019

@kgaikwad @ezr-ondrej LGTM overall, thank you! 😃

One small request, is it possible to add a test for this? I'm asking since all the integrations I maintain do not use this so I want to make sure we don't break your use-case down the road.

It should be super-trivial - just add a test method to https://github.com/fog/fog-google/blob/master/test/integration/compute/core_compute/test_servers.rb

Something like:

  def test_key_add
      server = @factory.create
      server.add_key(...)
      # Add the assertion here
  end

If you don't have time for it I understand. Just give me an example of your interaction and how you generate the key so I can add one later.

@Temikus Temikus merged commit 4fb3989 into fog:master Jun 7, 2019
@kgaikwad
Copy link
Contributor Author

kgaikwad commented Jun 11, 2019

@Temikus, thank you for merging this change and sorry for delay in response.
For Generating private and public SSH keys, we are using gem sshkey.
While creating instance, I am providing a public key along with user (which varies per image).

I will create pull-request which will add small test as you suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need fix while generating metadata for ssh_keys
4 participants