cisagov / action-lineage

Creative Commons Zero v1.0 Universal
5 stars 6 forks source link

Private repositories can not be handled, missing auth #43

Open Xerkus opened 2 years ago

Xerkus commented 2 years ago

🐛 Summary

Private repositories can not be processed due to check for lineage configuration never returning result from unauthenticated request: https://github.com/cisagov/action-lineage/blob/3a0be21e6c85e835d46d11046ac05613ec2ff623/src/lineage/entrypoint.py#L110-L118

To reproduce

Steps to reproduce the behavior:

  1. Setup action normally for private repository scanning
  2. Setup private repository and ensure PAT provides access
  3. Declare lineage configuration in private repository
  4. Trigger action and ensure repository was scanned:
    INFO Querying for repositories: user:Xerkus archived:false
    Xerkus/private-lineage-test
      INFO Checking: Xerkus/private-lineage-test
      INFO Lineage configuration not found for Xerkus/private-lineage-test
  5. Make repository public and observe action working as expected

Expected behavior

Lineage action can get past the check for lineage configuration existence

Any helpful log output or screenshots

mcdonnnj commented 2 years ago

@Xerkus Would you try the improvement/use_github_api_for_all_access branch and see if things work as you expect?

Xerkus commented 2 years ago

Lineage configuration is found, but it fails at cloning the repo.

mcdonnnj commented 2 years ago

Lineage configuration is found, but it fails at cloning the repo.

Ahh, sorry. I made a poor assumption about cloning behavior so I apologize. I have made a composition branch for testing because the two changes needed to resolve your issues belong in their own PRs. Would you try the testing/private_repo_access branch and let me know if things work as you expect this time?

Xerkus commented 2 years ago

Yes, this issue is resolved in the testing/private_repo_access branch.

The error that I see now is #44 when trying to fetch the upstream:

  INFO Checking: Xerkus/private-lineage-test
  INFO Lineage configuration found for Xerkus/private-lineage-test
  INFO Cloning repository: https://github.com/Xerkus/private-lineage-test.git
  INFO ✅ success
  INFO Processing lineage: skeleton
  INFO Upstream: https://github.com/Xerkus/private-lineage-test.git HEAD
  INFO Attempting to switch to branch: lineage/skeleton
  INFO ✅ (error ok) return code: 128
  INFO Branch did not exist.  Creating: lineage/skeleton from local main
  INFO Creating branch lineage/skeleton from main
  INFO ✅ success
  INFO Switching to lineage/skeleton
  INFO ✅ success
  INFO Pull request branch is new: True
  INFO Fetching https://github.com/Xerkus/private-lineage-parent.git HEAD
  Traceback (most recent call last):
  CRITICAL fatal: could not read Username for 'https://github.com': No such device or address

  CRITICAL ❌ ERROR! return code: 128
    File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
      exec(code, run_globals)
    File "/src/lineage/__main__.py", line 5, in <module>
      main()
    File "/src/lineage/entrypoint.py", line 455, in main
      fetch(repo, remote_url, remote_branch)
    File "/src/lineage/entrypoint.py", line 163, in fetch
      run([GIT, "fetch", remote_url, remote_branch], cwd=repo.full_name)
    File "/src/lineage/entrypoint.py", line 69, in run
      raise Exception("Subprocess was expected to exit with 0.")
  Exception: Subprocess was expected to exit with 0.

https://github.com/cisagov/action-lineage/blob/68d1458f5a582669cbd51ebbb3bed7ea5d5c1f0a/src/lineage/entrypoint.py#L455