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

added support to sign linux artifacts #1352

Merged

Conversation

abhinavGupta16
Copy link
Contributor

@abhinavGupta16 abhinavGupta16 commented Dec 16, 2021

Signed-off-by: Abhinav Gupta abhng@amazon.com

Description

Automate linux signing to sign any artifact or all artifacts in a directory

Issues Resolved

#1351
#1382

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Abhinav Gupta <abhng@amazon.com>
@abhinavGupta16 abhinavGupta16 self-assigned this Dec 16, 2021
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
@codecov-commenter
Copy link

codecov-commenter commented Dec 16, 2021

Codecov Report

Merging #1352 (eed9b7f) into main (ea5a964) will increase coverage by 0.06%.
The diff coverage is 97.05%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1352      +/-   ##
============================================
+ Coverage     94.02%   94.08%   +0.06%     
  Complexity       11       11              
============================================
  Files           136      139       +3     
  Lines          3011     3061      +50     
  Branches          8        8              
============================================
+ Hits           2831     2880      +49     
- Misses          172      173       +1     
  Partials          8        8              
Impacted Files Coverage Δ
src/sign_workflow/signer.py 94.11% <90.00%> (-2.66%) ⬇️
src/sign_workflow/sign_artifacts.py 98.03% <98.03%> (ø)
src/run_sign.py 95.23% <100.00%> (+2.64%) ⬆️
tests/jenkins/jobs/PromoteArtifacts_Jenkinsfile 100.00% <0.00%> (ø)
.../jenkins/jobs/PromoteArtifacts_actions_Jenkinsfile 100.00% <0.00%> (ø)

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 ea5a964...eed9b7f. Read the comment docs.

Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
src/sign_workflow/sign_existing_artifacts.py Outdated Show resolved Hide resolved
src/run_sign.py Outdated Show resolved Hide resolved
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
src/run_sign.py Outdated Show resolved Hide resolved
src/run_sign.py Outdated Show resolved Hide resolved
src/run_sign.py Outdated Show resolved Hide resolved
src/run_sign.py Outdated Show resolved Hide resolved
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
tests/test_run_sign.py Outdated Show resolved Hide resolved
vars/signArtifacts.groovy Outdated Show resolved Hide resolved
vars/signArtifacts.groovy Outdated Show resolved Hide resolved
vars/signArtifacts.groovy Outdated Show resolved Hide resolved
vars/signArtifacts.groovy Outdated Show resolved Hide resolved
dblock
dblock previously requested changes Dec 17, 2021
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Close!

src/run_sign.py Outdated
from system import console

ACCEPTED_SIGNATURE_FILE_TYPES = [".sig", ".asc"]
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this already Signer.ACCEPTED_FILE_TYPES? Use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is accepted Signature types, different from accepted file types

src/run_sign.py Outdated Show resolved Hide resolved
src/sign_workflow/sign_artifacts.py Outdated Show resolved Hide resolved
src/sign_workflow/sign_artifacts.py Outdated Show resolved Hide resolved

def __sign__(self):
artifacts = [self.target.name]
basename = self.target.parent
Copy link
Member

Choose a reason for hiding this comment

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

These variables aren't reused, just pass the arguments as is below.

Add __sign_artifact__ that takes one artifact.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Variables just make it clear as to what is being passed to the function. I think we can leave it like this

src/sign_workflow/signer.py Show resolved Hide resolved
src/sign_workflow/sign_artifacts.py Outdated Show resolved Hide resolved
tests/tests_sign_workflow/test_sign_artifacts.py Outdated Show resolved Hide resolved

self.assertEqual(type(SignWithManifest), type(klass))

path = Path(r"/dummy/path/")
Copy link
Member

Choose a reason for hiding this comment

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

Split up in separate tests.

Copy link
Contributor Author

@abhinavGupta16 abhinavGupta16 Dec 18, 2021

Choose a reason for hiding this comment

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

I think it should be one method, since it just verifies multiple if conditions with no workflow. It would just increase verbosity and complexity. This is clear too.

Copy link
Member

Choose a reason for hiding this comment

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

It's not a must have, but my reasoning is that these tests can fail independently, and methods are cheap.

artifact_type = 'dummy'
sigtype = '.asc'

klass = SignArtifacts.from_path(path, component, artifact_type, sigtype)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, split up into individual tests for each type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same reason as before.

Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
tests/tests_sign_workflow/test_sign_artifacts.py Outdated Show resolved Hide resolved

self.assertEqual(type(SignWithManifest), type(klass))

path = Path(r"/dummy/path/")
Copy link
Member

Choose a reason for hiding this comment

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

It's not a must have, but my reasoning is that these tests can fail independently, and methods are cheap.

tests/tests_sign_workflow/test_sign_artifacts.py Outdated Show resolved Hide resolved
Copy link
Member

@peternied peternied 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 addressing my comments, great work enhancing this flow.

Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
@abhinavGupta16 abhinavGupta16 linked an issue Dec 19, 2021 that may be closed by this pull request
5 tasks
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Signed-off-by: Abhinav Gupta <abhng@amazon.com>
@abhinavGupta16 abhinavGupta16 marked this pull request as ready for review December 21, 2021 02:50
@abhinavGupta16
Copy link
Contributor Author

Thanks @dblock for helping out with the test cases

Signed-off-by: Abhinav Gupta <abhng@amazon.com>
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Works for me.

I would also remove all the passing around of Signer() which is always the same class, and create an instance of it at the lowest level.

"".join(pathlib.Path(file_name).suffixes),
]
for x in Signer.ACCEPTED_FILE_TYPES
file_name.endswith(x) for x in Signer.ACCEPTED_FILE_TYPES
Copy link
Member

Choose a reason for hiding this comment

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

Use os.path.splitext to get the extension from the file name, then in to check ether it’s one of the accepted types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does not work since we have artifacts with names like opensearch-1.0.0.tar.gz. That is why I changed it to endswith

Copy link
Member

Choose a reason for hiding this comment

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

We could just change .tar.gz into .gz. Technically the extension of that file is not .tar.gz, it’s .gz.

@abhinavGupta16 abhinavGupta16 dismissed dblock’s stale review December 21, 2021 19:42

@dblock approved the changes on behalf of opensearch-project/engineering-effectiveness

@abhinavGupta16 abhinavGupta16 merged commit c18e136 into opensearch-project:main Dec 21, 2021
@abhinavGupta16 abhinavGupta16 deleted the abhng-sign-artifacts branch December 21, 2021 19:44
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.

upgrade Signer.py to be able to sign artifacts with .sig in a directory
5 participants