<@U08614ZV82F> Any common gotchas on the github sy...
# permit-saas
a
@Ask Inkeep Any common gotchas on the github sync? I used the bash script and followed the instructions exactly but ended up with
Cannot activate repository due to invalid status.
I'm unsure what to change to make it valid. Tried on the main repo for the project as well as a new blank repo with a single commit. It mentioned somewhere about not having 2fa enabled. I do have that enabled on my account, but I don't think it applies to the deploy hooks
a
Thanks for tagging me @Abe Clark. I'll look through relevant sources and get back to you shortly.
The "Cannot activate repository due to invalid status" error typically occurs when the repository hasn't been properly validated yet. Here are the key points to check: Repository Validation Process After configuring your repository with the POST request, you need to verify that new branches were created before attempting activation (1) . The branches should be named following the format
permit/generated/<env_id>
. 2FA and Deploy Keys Regarding your 2FA concern - the documentation specifically states that deploy keys should be set up *without Two-Factor Authentication (2FA) * to allow the Permit server unrestricted read and write access to your repository . While 2FA on your account doesn't directly affect deploy keys, this requirement suggests ensuring the deploy key has unimpeded access. Activation Steps The activation process requires two separate API calls : 1. First, the POST request to configure the repository:
Copy code
curl -X POST "<https://api.permit.io/v2/projects/<your-project-id-or-key>/repos>" -H "Content-Type: application/json" -H "Authorization: Bearer {API_KEY from step 4}" --data-binary @"path/to/your/json"
2. Then, after validating the policy branches exist, the PUT request to activate:
Copy code
curl -X PUT "<https://api.permit.io/v2/projects/<your-project-id-or-key>/repos/<your-repo-id-or-key>/activate>" -H "Authorization: Bearer <your-permit-api-key>"
Common Issues to Check 1. ​*Branch Creation*​: Verify that the
permit/generated/<env_id>
branches were created in your repository after the initial POST request 2. ​*SSH Key Format*​: Ensure your private key uses proper newline replacement with
\n
using:
awk -v ORS='\\n' '1' <private-key-file>
3. ​*Deploy Key Permissions*​: Confirm the deploy key has "Allow write access" toggled on in GitHub 4. ​*Repository State*​: The repository needs a default branch with at least one commit on the remote Try checking your repository for the generated branches first. If they don't exist, the initial configuration may have failed, preventing activation.
To learn more, see the sources I considered: [[1] Git and Permit](https://docs.permit.io/integrations/gitops/github)
a
The branches were never created @Ask Inkeep Are there specific debug steps for that failure?
a
Thanks for tagging me @Abe Clark. I'll look through relevant sources and get back to you shortly.
If the branches were never created, this indicates the initial POST request to create the repository configuration failed. Here are specific debugging steps: ​*Check Repository Creation Status*​ According to the documentation, the repository is created with status 'pending' and will only be changed to 'active' after a successful attempt to use it (1) . The repository main branch must be present in the remote . ​*Common Configuration Issues to Debug*​ 1. ​*SSH Key Format*​: Ensure your private key is properly formatted with newline replacement :
Copy code
awk -v ORS='\\n' '1' <private-key-file>
2. ​*JSON Configuration Structure*​: Verify your JSON file has the correct structure :
Copy code
{
  "url": "<your-ssh-url>",
  "main_branch_name": "<your-default-branch>",
  "credentials": {
    "auth_type": "ssh",
    "username": "git",
    "private_key": "<your-private-key>"
  },
  "key": "<your-custom-id-string-without-spaces>"
}
3. ​*Repository Requirements*​: • The repository needs at least one file committed when using GitOps with a brand-new Git repository that has no commits on the main branch (2) • The repository main branch must be present in the remote (1) ​*API Response Debugging*​ Check the response from your initial POST request - it should return a PolicyRepoRead object if successful (3) (4) . Any 422 error would indicate validation issues with your configuration (3) . ​*Related Known Issues*​ There's a documented case where OPAL failed to checkout a repository due to configuration issues with wrong URL, key, or protocol (5) . The error "policy repo was not found" can occur when OPAL tries checking out your repository and fails . Try running the POST request again and capture the full response to see if there are specific error details about why the repository configuration isn't being accepted.
To learn more, see the sources I considered: [[1] Git and Permit](https://docs.permit.io/integrations/gitops/github) [[2] Create a new Environment](https://docs.permit.io/manage-your-account/creating-environments) [[3] permitio/permit-golang/pkg/openapi/api_policy_git_repositories.go](https://github.com/permitio/permit-golang/blob/master/pkg/openapi/api_policy_git_repositories.go) [[4] permitio/permit-ruby/lib/openapi_client/api/policy_git_repositories_api.rb](https://github.com/permitio/permit-ruby/blob/main/lib/openapi_client/api/policy_git_repositories_api.rb) [[5] Getting a 503 on GET /policy?path=. but no errors anywhere being outputted](https://github.com/permitio/opal/discussions/510)
a
I got back
"status":"pending"
from the intial call, but the second one fails:
Copy code
{
  "id": "5d25e34283d6447590171ce6ef1e9527",
  "title": "The request was invalid",
  "error_code": "INVALID_POLICY_REPO_STATUS",
  "message": "Your policy repo haven't changed, you have tried to activate policy repo with status 'invalid' which is illegal. Please verify that the Policy Repo status is valid.\nIf the Policy Repo is valid, contact our support on Slack for further guidance."
}
@Ask Inkeep See previous message
a
Thanks for tagging me @Abe Clark. I'll look through relevant sources and get back to you shortly.
The error shows your repository status is
invalid
rather than
valid
. According to the SDK documentation, a PolicyRepoStatus can have three states (1) :
Copy code
"invalid",
"pending",
"valid",
Your repository went from
pending
to
invalid
, which means the validation failed. The repository is created with status 'pending' and will only change to 'valid' after successful validation (2) (3) . Since you're experiencing issues with repository validation and the branches weren't created, here's what our engineers need to investigate: 1. ​*Which Workspace / Project / Env are you using?*​ (Please provide the specific IDs or keys) 2. ​*What exact API calls are you making?*​ (Share the full CURL commands with parameters, excluding sensitive tokens) 3. ​*Which PDP version are you running?*​ (If you have a PDP deployed) 4. ​*Can you share relevant logs?*​ Particularly any error messages from when the repository validation fails The
invalid
status indicates the system couldn't successfully connect to or validate your repository. Common causes include SSH key issues, repository access problems, or branch creation failures.
o
Hi abe consider also using our CLI tool to setup the connection. Furthermore often this type of error is when the secret is not setup correctly
@Ask Inkeep
a
Thanks for tagging me @Or Weis. I'll look through relevant sources and get back to you shortly.
Feel free to tag me with additional questions. I also appreciate feedback, it helps me improve. 👍 button 👎 button
a
used the local CLI and it just hung on:
Copy code
permit gitops create github

 GitOps Configuration Wizard - GitHub


 Your GitOps is configured successfully and 
 will be activated once validated
never returned. No new branches pushed.
p
Hey, thanks for reaching out ! It seems our team is a little busy right now, a human will be with you within the next hour or so. In the meantime, can I help you ?
o
Did you try it on a clean-slate environment? Previous. Previous configurations might conflict. Are you able to connect to the repo manually with the SSH key you've created?