Skip to content

SECURITY-59: Add GHA workflows#63

Merged
Xiangs18 merged 36 commits intodevelopfrom
dev-add_workflows
May 19, 2025
Merged

SECURITY-59: Add GHA workflows#63
Xiangs18 merged 36 commits intodevelopfrom
dev-add_workflows

Conversation

@Xiangs18
Copy link
Copy Markdown
Contributor

No description provided.

Comment on lines +16 to +19
if: github.base_ref == 'develop' && github.event.pull_request.merged == false
uses: kbase/.github/.github/workflows/reusable_build.yml@main
secrets: inherit
build-develop-merge:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
Comment on lines +20 to +26
if: github.base_ref == 'develop' && github.event.pull_request.merged == true
uses: kbase/.github/.github/workflows/reusable_build-push.yml@main
with:
name: '${{ github.event.repository.name }}-develop'
tags: pr-${{ github.event.number }},latest
secrets: inherit
build-main-open:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
Comment on lines +27 to +33
if: (github.base_ref == 'main' || github.base_ref == 'master') && github.event.pull_request.merged == false
uses: kbase/.github/.github/workflows/reusable_build-push.yml@main
with:
name: '${{ github.event.repository.name }}'
tags: pr-${{ github.event.number }}
secrets: inherit
build-main-merge:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
Comment on lines +34 to +40
if: (github.base_ref == 'main' || github.base_ref == 'master') && github.event.pull_request.merged == true
uses: kbase/.github/.github/workflows/reusable_build-push.yml@main
with:
name: '${{ github.event.repository.name }}'
tags: pr-${{ github.event.number }},latest-rc
secrets: inherit
trivy-scans:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
Comment on lines +41 to +43
if: (github.base_ref == 'develop' || github.base_ref == 'main' || github.base_ref == 'master' ) && github.event.pull_request.merged == false
uses: kbase/.github/.github/workflows/reusable_trivy-scans.yml@main
secrets: inherit

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
Comment on lines +11 to +14
uses: kbase/.github/.github/workflows/reusable_validate-branch.yml@main
with:
build_branch: '${{ github.event.release.target_commitish }}'
validate-release-tag:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
Comment on lines +15 to +19
needs: check-source-branch
uses: kbase/.github/.github/workflows/reusable_validate-release-tag.yml@main
with:
release_tag: '${{ github.event.release.tag_name }}'
build-push:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
Comment on lines +20 to +25
needs: validate-release-tag
uses: kbase/.github/.github/workflows/reusable_build-push.yml@main
with:
name: '${{ github.event.repository.name }}'
tags: '${{ github.event.release.tag_name }},latest'
secrets: inherit

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
@github-advanced-security
Copy link
Copy Markdown

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e17f604) to head (efa12c8).
Report is 37 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff            @@
##           develop       #63   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        21    +1     
  Lines          658       660    +2     
=========================================
+ Hits           658       660    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Xiangs18 Xiangs18 changed the title [WIP] SECURITY-59: Add GHA workflows SECURITY-59: Add GHA workflows May 6, 2025
@Xiangs18
Copy link
Copy Markdown
Contributor Author

Xiangs18 commented May 6, 2025

self note:

  • - ensure integration tests pass locally
  • - add some readmes in jsonrpc directories explaining what's going on, why they're vendored, and where the code came from

@Xiangs18
Copy link
Copy Markdown
Contributor Author

Screenshot 2025-05-13 at 11 41 09 AM

@Xiangs18 Xiangs18 requested review from MrCreosote and bio-boris May 13, 2025 22:57
Comment thread .github/codeql.yml
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Standard question about boilerplate GHA yamls

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

standard boilerplate GHA yamls

Comment thread jsonrpc11base/README.md
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not reviewing the vendored code here, assuming it's an exact C&P. If that's not true LMK

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

exact C&P

Comment thread jsonrpcbase/README.md
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not reviewing the vendored code here, assuming it's an exact C&P. If that's not true LMK

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

exact C&P

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did add one line to fix the failing unit test; otherwise, it would raise a KeyError.

-32003: 'Elasticsearch response error',

Copy link
Copy Markdown
Member

@MrCreosote MrCreosote May 14, 2025

Choose a reason for hiding this comment

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

That suggests we're using the wrong version of this library, if there's a missing handler for an internal exception

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, so the last commit for jsonrpcbase is alpha5: https://github.com/kbaseincubator/jsonrpcbase/commits/master/

But this codebase is using alpha6

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

... never mind the fact that the codebase is using something labeled with an alpha at all

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread tests/helpers/integration_setup.py Outdated
Comment on lines +43 to +45
container_process.send_signal(signal.SIGTERM)

# Stop and remove containers
cwd = 'tests/integration/docker'
subprocess.run("docker-compose --ansi never down", shell=True, check=True, cwd=cwd)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was because the old code could not successfully shut down the container, which caused errors in the integration tests. My current code fixes this problem.

Screenshot 2025-05-13 at 4 30 37 PM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What changed such that the container no longer shuts down correctly?

Copy link
Copy Markdown
Contributor Author

@Xiangs18 Xiangs18 May 13, 2025

Choose a reason for hiding this comment

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

I'm not sure what you're asking. I didn't change anything that would cause the container to stop shutting down. It simply doesn't shut down when I start running the integration tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Presumably the integration tests worked at some point in the past. That means that something changed so that the prior method of shutting down the container stopped working. I'm wondering what that change was.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it needs to be logger.warning; otherwise, the unit test would not pass either.

We need to switch to docker-compose down approach. It was designed for this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The reason I'm continuing to ask questions is that the service should respond to a sigterm. What we're seeing is that it's not, and (I assume) the reason docker compose down is working is that it's sending a sigterm, waiting 10 seconds, and then sending a sigkill.

All that being said, this is pretty good evidence that I was wrong, and the devs did allow the tests to pass without the service responding to a sigterm: 728b712

As such, can you make an issue noting that the service / container needs to be updated to respond to sigterm correctly, and then go ahead with the docker compose down fix for now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Without the or change, does it time out and print the warning?

If I change logger.warning to Exception in the unit tests, it will raise a timeout error. Now it kind of justifies why logger.warning is used in the unit tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh great, there's a commit to verify my comment!
#63 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed by docker compose to shut down the container/service
issue created: #64

Comment thread tests/helpers/integration_setup.py Outdated
Comment on lines +46 to +50
if not common.wait_for_line("container.err",
lambda line: 'Stopping' in line and 'done' in line,
if not common.wait_for_line("container.out",
lambda line: "exited with code 0" in line,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question - why the change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Running docker-compose down shuts the containers down gracefully, as confirmed by the presence of the "exited with code 0" message in the container.out file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sending a sigterm also shuts the containers down gracefully. If a sigterm isn't enough, then docker is sending a sigkill which isn't a graceful shutdown

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When using container_process.send_signal(signal.SIGTERM), Docker will not automatically send a SIGKILL if the container does not stop. The behavior you described applies to docker stop and docker-compose.

Copy link
Copy Markdown
Member

@MrCreosote MrCreosote May 14, 2025

Choose a reason for hiding this comment

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

Right, what I'm saying is that the container shouldn't require a sigkill to stop - it should respond to just a sigterm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

assert res['error']
assert res['error']['code'] == -32003
assert res['error']['message'] == 'Server error'
assert res['error']['message'] == 'Elasticsearch response error'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did this change? This seems like a bug that should be fixed in the search api rather than adjusting the tests. I'm guessing an exception changed and is no longer being caught correctly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Based on the README documentation, -32003 represents an "Elasticsearch response error." This is also asserted on line 52. Additionally, I traced the code, and if it's correct, it should be raising an Elasticsearch response error.

raise ElasticsearchError(resp.text)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is probably related to #63 (comment)

The code in this PR is a revision behind that in the requirements toml file. I'd guess this is fixed in in the alpha 6 release

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where is the Alpha6 release? Alpha5 is the vendored repository that we are currently using. Am i missing something?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Search requires alpha 6, not alpha 5: https://github.com/kbase/search_api2/blob/develop/pyproject.toml#L14

As far as where that code lives, none of the branches in the jsonrpcbase repo look promising since they're all behind master. I'd extract it from pypi and update the readme to explain where the code came from

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Extracted jsonrpc alpha6 from PyPI, and the unit test passed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you have to make any changes or is it just strict C&P now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a direct copy with no changes. The only difference between alpha5 and alpha6 is the line 'message': RPC_ERRORS.get(code, 'Server error') in the main.py file.

Comment on lines 157 to +166
def test_search_objects_private_and_public_counts(service):
assert_counts(service, 1, 1, 12)
assert_counts(service, 1, 1, 21)


def test_search_objects_private_counts(service):
assert_counts(service, 1, 0, 5)
assert_counts(service, 1, 0, 12)


def test_search_objects_public_counts(service):
assert_counts(service, 0, 1, 9)
assert_counts(service, 0, 1, 11)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just to be sure and leave a record: The data returned from the search api is a super set of the objects and workspaces in the response files in this repo, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I verified that the data returned from the search API is a superset of the objects and workspaces in the response files (case-03-response.json) in this repository.

@Xiangs18 Xiangs18 requested a review from MrCreosote May 16, 2025 21:37
Copy link
Copy Markdown
Member

@MrCreosote MrCreosote left a comment

Choose a reason for hiding this comment

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

Note to self: all comments above this review are resolved

Comment thread jsonrpcbase/README.md
Comment on lines +3 to +9
Simple JSON-RPC service without transport layer.

This repository includes a vendored copy of [jsonrpcbase](https://github.com/kbaseincubator/jsonrpcbase) to resolve dependency conflicts.

Specifically, this is version kbase-jsonrpcbase 0.3.0a6, extracted from [pypi](https://pypi.org/project/kbase-jsonrpcbase/)

The original repository was only used by this project, so the code has been brought in directly to simplify maintenance and eliminate external dependency issues. No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Simple JSON-RPC service without transport layer.
This repository includes a vendored copy of [jsonrpcbase](https://github.com/kbaseincubator/jsonrpcbase) to resolve dependency conflicts.
Specifically, this is version kbase-jsonrpcbase 0.3.0a6, extracted from [pypi](https://pypi.org/project/kbase-jsonrpcbase/)
The original repository was only used by this project, so the code has been brought in directly to simplify maintenance and eliminate external dependency issues.
Simple JSON-RPC service without transport layer.
This repository includes a vendored copy of [jsonrpcbase](https://pypi.org/project/kbase-jsonrpcbase/) version `0.3.0a6` to resolve dependency conflicts.
Note that there exists a [github repo](https://github.com/kbaseincubator/jsonrpcbase) which is presumably the source of the PyPi module, but it appears to only contain the alpha5 release of the code vs. PyPi's alpha6. It is not clear where the alpha6 code resides other than PyPi,
The original repository was only used by this project, so the code has been brought in directly to simplify maintenance and eliminate external dependency issues.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍

Comment thread tests/helpers/integration_setup.py Outdated
Comment on lines 47 to 53
logger.info('Waiting until service has stopped...')

if not common.wait_for_line("container.err",
lambda line: 'Stopping' in line and 'done' in line,
if not common.wait_for_line("container.out",
lambda line: "exited with code 0" in line,
timeout=stop_timeout,
line_count=1):
raise Exception(f'Container did not stop in the alloted time of {stop_timeout} seconds')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since subprocess run will block until docker compose down is complete, I don't think all this checking code does anything anymore. It won't run until the down is finished

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe this check is useful and necessary because it verifies that the containers are actually shutting down.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

They must be down at this point. Run blocks until the command exits, and check ensures that the exit code is 0. If not, an exception will be thrown. This code can only be reached if the containers are down

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interestingly the tests are no longer passing. I don't see how the changes you made could've caused that...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2025-05-16 at 5 49 02 PM

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed .common

Comment thread tests/helpers/unit_setup.py Outdated
Comment on lines 47 to 55
logger.info('Waiting until service has stopped...')
if not common.wait_for_line("container.err",
lambda line: 'Stopping' in line and 'done' in line,
if not common.wait_for_line("container.out",
lambda line: "exited with code 0" in line,
timeout=stop_timeout,
line_count=2):

# Use logger.warning here to allow tests to pass in CI.
# Note: Containers shut down properly when run locally, but may not behave the same in CI environments.
logger.warning(f'Container did not stop in the alotted time of {stop_timeout} seconds')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment as above

Copy link
Copy Markdown
Member

@MrCreosote MrCreosote left a comment

Choose a reason for hiding this comment

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

LGTM. @bio-boris do you want to review?

@Xiangs18 Xiangs18 merged commit 23ec7c1 into develop May 19, 2025
12 checks passed
@Xiangs18 Xiangs18 deleted the dev-add_workflows branch May 19, 2025 17:53
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.

4 participants