-
Notifications
You must be signed in to change notification settings - Fork 278
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
Add signer to support signing windows artifacts #2156
Merged
peterzhuamazon
merged 17 commits into
opensearch-project:main
from
zelinh:sign-for-windows
Jun 30, 2022
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
96ab66c
Add signer for windows distribution and implement the jenkins libarar…
zelinh 6c1fe26
Replace platform with MagicMock for testing
zelinh 2046f48
Change to not initiate signer for mock case
zelinh 94e6cd5
Change the default signature type to .asc for compatibility with old …
zelinh 916cca3
Resolve upstream conflict with signArtifacts
zelinh 6f953fa
Add signer abstract class
zelinh 737010b
Remove abstract method
zelinh eae3457
Commit test cases
zelinh 1a6ae64
Fix python tests
zelinh 6eb0385
Remove unused library import
zelinh 9a7f2f5
Fix mock repo tests
zelinh 069863e
Merge remote-tracking branch 'upstream/main' into sign-for-windows
zelinh fd65413
Remove commmented block
zelinh 5129326
Fix the python tests and combine credentials
zelinh 1e1a56e
Change path for windows tests
zelinh 3906d09
Resolve conflicts
zelinh d36beb9
Fix more conflict
zelinh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
from sign_workflow.signer import Signer | ||
|
||
""" | ||
This class is responsible for signing an artifact using the OpenSearch-signer-client and verifying its signature. | ||
The signed artifacts will be found in the same location as the original artifacts. | ||
""" | ||
|
||
|
||
class SignerPGP(Signer): | ||
|
||
ACCEPTED_FILE_TYPES = [".zip", ".jar", ".war", ".pom", ".module", ".tar.gz", ".whl", ".crate", ".rpm"] | ||
|
||
def generate_signature_and_verify(self, artifact: str, basepath: Path, signature_type: str) -> None: | ||
location = os.path.join(basepath, artifact) | ||
self.sign(artifact, basepath, signature_type) | ||
self.verify(location + signature_type) | ||
|
||
def is_valid_file_type(self, file_name: str) -> bool: | ||
return any( | ||
file_name.endswith(x) for x in SignerPGP.ACCEPTED_FILE_TYPES | ||
) | ||
|
||
def sign(self, artifact: str, basepath: Path, signature_type: str) -> None: | ||
filename = os.path.join(basepath, artifact) | ||
signature_file = filename + signature_type | ||
self.__remove_existing_signature__(signature_file) | ||
signing_cmd = [ | ||
"./opensearch-signer-client", | ||
"-i", | ||
filename, | ||
"-o", | ||
signature_file, | ||
"-p", | ||
"pgp", | ||
] | ||
self.git_repo.execute(" ".join(signing_cmd)) | ||
|
||
def verify(self, filename: str) -> None: | ||
verify_cmd = ["gpg", "--verify-files", filename] | ||
self.git_repo.execute(" ".join(verify_cmd)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
from sign_workflow.signer import Signer | ||
|
||
""" | ||
This class is responsible for signing an artifact using the OpenSearch-signer-client and verifying its signature. | ||
The signed artifacts will be found in the subfolder called signed under the origin location as the original artifacts. | ||
""" | ||
|
||
|
||
class SignerWindows(Signer): | ||
|
||
ACCEPTED_FILE_TYPES = [".msi", ".exe", ".dll", ".sys", ".ps1", ".psm1", ".psd1", ".cat", ".zip"] | ||
|
||
def generate_signature_and_verify(self, artifact: str, basepath: Path, signature_type: str) -> None: | ||
self.sign(artifact, basepath, signature_type) | ||
|
||
def is_valid_file_type(self, file_name: str) -> bool: | ||
return any( | ||
file_name.endswith(x) for x in SignerWindows.ACCEPTED_FILE_TYPES | ||
) | ||
|
||
def sign(self, artifact: str, basepath: Path, signature_type: str) -> None: | ||
filename = os.path.join(basepath, artifact) | ||
signed_prefix = "signed_" | ||
signature_file = os.path.join(basepath, signed_prefix + artifact) | ||
self.__remove_existing_signature__(signature_file) | ||
signing_cmd = [ | ||
"./opensearch-signer-client", | ||
"-i", | ||
filename, | ||
"-o", | ||
signature_file, | ||
"-p", | ||
"windows", | ||
] | ||
self.git_repo.execute(" ".join(signing_cmd)) | ||
signed_folder = os.path.join(basepath, "signed") | ||
if not os.path.exists(signed_folder): | ||
os.mkdir(signed_folder) | ||
signed_location = os.path.join(signed_folder, artifact) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zelinh please create an issue to add a verification of the windows signing. |
||
os.rename(signature_file, signed_location) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
|
||
|
||
from sign_workflow.signer import Signer | ||
from sign_workflow.signer_pgp import SignerPGP | ||
from sign_workflow.signer_windows import SignerWindows | ||
|
||
|
||
class Signers: | ||
TYPES = { | ||
"windows": SignerWindows, | ||
"linux": SignerPGP, | ||
} | ||
|
||
@classmethod | ||
def from_platform(cls, platform: str) -> Signer: | ||
klass = cls.TYPES.get(platform, None) | ||
if not klass: | ||
raise ValueError(f"Unsupported type of platform for signing: {platform}") | ||
return klass # type: ignore[return-value] | ||
|
||
@classmethod | ||
def create(cls, platform: str) -> Signer: | ||
klass = cls.from_platform(platform) | ||
return klass() # type: ignore[no-any-return, operator] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zelinh Please just remove the original file and upload the signed file like RPM in a new PR.
Then signed/signed structure is just very confusing.
Thanks.