Unable to Clone from Google Cloud Source Repository - google-cloud-platform

I have created a project (ID: imagetest1-259203) within an organization. I successfully created a repository using
gcloud source repos create repo1
but when I tried to clone this to my PC using
gcloud source repos clone repo1
I get the following issue. (Note: I already have enabled "Cloud Source Repositories API")
Cloning into 'D:\AppEngineTests\repo1'...
remote: PERMISSION_DENIED: The caller does not have permission
remote: [type.googleapis.com/google.rpc.RequestInfo]
remote: request_id: "2e79f3c507f14b3190d7a5941bed3e5f"
fatal: unable to access 'https://source.developers.google.com/p/imagetest1-259203/r/repo1/': The requested URL returned error: 403
ERROR: (gcloud.source.repos.clone) Command '[u'git', u'clone', u'https://source.developers.google.com/p/imagetest1-259203/r/repo1', u'D:\\AppEngineTests\\repo1', u'--config', u'credential.helper=', u'--config', u'credential.helper=!gcloud.cmd auth git-helper --account=prabodar#xellmart.com --ignore-unknown $#']' returned non-zero exit status 128
But when I cloned to Cloud Shell using the same set of commands, it succeeded.

In order to clone the contents of a Google Cloud Repository you need:
authentication on your local system
a repository in Cloud Source Repositories
permissions to interact with the repository link
I suspect you have issues with permissions.
You have to install Cloud SDK.
Provide your authentication credentials:
gcloud init
and then clone the repository:
gcloud source repos clone [REPO_NAME] --project=[PROJECT_NAME]

I had this issue for months, I was using two different accounts, personal & work.
It worked on one PC, but not another PC.
FIX: Rename or delete this file: %USERPROFILE%_netrc
I tried:
gcloud auth revoke + then gcloud auth init
Renamed .gitconfig
Renamed .gitcookies
Deleted %USERPROFILE%\AppData\Roaming\gcloud
Deleted creds from Windows Credential Manager with 'git'
Eventually ran procmon to trace which files it was reading.
Renamed _netrc to _netrc.backup
Command then worked.
Undid rename and tested again, returned error message once again.

Related

GCP ci/cd: skaffold cannot access private git repository using google cloud build

I'm trying to configure auto ci/cd process with google cloud platform.
So I went through this instruction https://davelms.medium.com/automate-gke-deployments-using-cloud-build-and-cloud-deploy-2c15909ddf22 and all works good. So I have a trigger in cloud build that goes to cloud build file that using skaffold for manifest rendering. It builds an image and deploy the app. All good.
But as we have a lot of apps we want to have deploy configs in the separate repo. In that case I see from skaffold docs https://skaffold.dev/docs/references/yaml/?version=v2beta29#build-artifacts-docker-ssh that you could use as configs:
requires:
- configs: []
git:
repo: https://github.com/GoogleContainerTools/skaffold.git
path: skaffold.yaml
ref: main
sync: true
this config works for public repo, but for private repo I get error:
error parsing skaffold configuration file: caching remote dependency https://github.com/your_repo.git: failed to clone repo: running [/usr/bin/git clone https://github.com/your_repo.git ./P7akUPb6jdsgjfgTnOedB92BH8UE7 --branch main --depth 1]
" - stderr: "Cloning into './P7akUPb6jdsgjfgTnOedB92BH8UE7'...\nfatal: could not read Username for 'https://github.com': No such device or address\n""
Where or how I could add details for accessing private repo?

Google Cloud Source Repository: remote: PERMISSION_DENIED: The caller does not have permission remote

remote: PERMISSION_DENIED: The caller does not have permission remote: [type.googleapis.com/google.rpc.RequestInfo]
Not able to clone, push the code into google cloud source repository. I have given "Project Editor" iam permission. I have successfully login with "gcloud login" command. I also have set the right default project configuration and account configuration using "gcloud config set project" and "gcloud config set account" commands. Please help me with this PERMISSION_DENIED error.
I had the exact same issue and I resolved it by adding a new entry in the .gitcookies file.
You have to manually generated and stored your Git credentials by login on this page: https://source.developers.google.com/auth/start?scopes=https://www.googleapis.com/auth/cloud-platform&state=
That will ask you to login with your account and allow Google Cloud Development wants to access your Google Account. Then, you'll have the script you have to run.
Hope this helps you as well.
For me it was that my free trial had ended and I needed to enable the billing here:
https://console.developers.google.com/billing/enable?project=[YOUR_PROJECT_ID]
For me this happened when I used SSH and connection re-use by a ControlMaster directive.
It seems like google's git implementation can't handle this.
For me either of these two worked:
close the ssh connection with ssh -O exit ... (add your connection)
delete the socket from the file system (specified by ControlPath)

Google Cloud Function Environment Variables Directory

I've got a Cloud Function working properly, but now I'd like to obfuscate some credentials with environmental variables. When I try running this command:
gcloud beta functions deploy my-function --trigger-http --set-env-vars user=username,pass=password --runtime nodejs6 --project my-project
I get this error:
ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, message=Function load error: File index.js or function.js that is expected to define function doesn't exist in the root directory.
I created the function using the GCP web UI, and I can't find the directory where the function lives to cd into. Presumably running the same command from the directory that the function lives in would work.
Where do cloud functions live in my project?
If you check the details of the function deployment on the logs, you'll notice field protoPayload.request.function.sourceUploadUrl contains a URL where your source code is uploaded during the deployment.
This URL is is in the form of https://storage.googleapis.com/gcf-upload-<region>-<random>/<random>.zip. This means that the function is uploaded that GCS bucket. That GCS bucket is not on your project (it's from Google), so you won't have direct access to the files. You can download the files stored on that bucket through the console (the "Download zip" button on the source page).
The upload bucket can also be found through
gcloud functions list --format='table[](name,sourceUploadUrl)'
Knowing this, you have 2 paths:
Use another way of deploying the function (e.g. from a source repo)
Use the API to patch the function
I'm partial to the second option, since it's really easy to execute:
curl -XPATCH -H"Authorization: Bearer $(gcloud auth print-access-token)" -H'content-type:application/json' 'https://cloudfunctions.googleapis.com/v1/projects/<PROJECT_ID>/locations/<REGION>/functions/<FUNCTION_ID>?updateMask=environmentVariables' -d'{"environmentVariables":{"user":"<USERNAME>", "password":"<PASSWORD>"}}'
However, if you need to access anywhere Google related, rather than pass user/password, it's best to use the application default credentials, and providing access to the service account on the resource. To find out the service account used by your function, you can run:
gcloud functions list --format='table[](name,serviceAccountEmail)'

Google Cloud - Wrong project id being used from different email address

Despite running gcloud auth application-default login and gcloud config set core/project CORRECT_PROJECT_ID the project keeps defaulting to an incorrect project id:
gcloud config list
[core]
account = CORRECT_EMAIL
disable_usage_reporting = True
project = CORRECT_PROJECT_ID
Your active configuration is: [default]
I can successfully run the sample code from the tutorial (below) if I run in the terminal
export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
However, I didn't want to have to do this every time, so I ran the command:
gcloud auth application-default login
This opened a browser with a list of my gmail accounts, and even though I selected the correct account, the success window went to a different gmail account. So then I tried it in an incognito window, and it worked.
However, running npm start resulted in the following error:
ERROR: { Error: 7 PERMISSION_DENIED: Cloud Natural Language API has not been used in project WRONG_PROJECT_ID before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/language.googleapis.com/overview?project=WRONG_PROJECT_ID then retry.
Then I ran gcloud config set core/project CORRECT_PROJECT_ID and got the message Updated property [core/project].
When I run npm start I get the same message:
ERROR: { Error: 7 PERMISSION_DENIED: Cloud Natural Language API has not been used in project WRONG_PROJECT_ID before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/language.googleapis.com/overview?project=WRONG_PROJECT_ID then retry.
I tried gcloud auth login and got the following message (after I authenticated in an incognito window):
WARNING: `gcloud auth login` no longer writes application default credentials.
If you need to use ADC, see:
gcloud auth application-default --help
You are now logged in as [CORRECT EMAIL ADDRESS].
Your current project is [CORRECT_PROJECT_ID]. You can change this setting by running:
$ gcloud config set project PROJECT_ID
I have a few suggestions that may correct this behaviour.
1) Clear your web browser cache & cookies. Then run "gcloud auth application-default login"
2) Try re-installing the gcloud toolkit.
3) Try unsetting the project in your config first, then set the project to the correct project. i.e.
gcloud config unset project WRONG_PROJECT_ID
gcloud config set project CORRECT_PROJECT_ID
4) Check the “CLOUDSDK_CORE_PROJECT” environment variable. Set it to the correct project if it is not already.
5) Try re-running “gcloud init”
6) You can find your application default credentials in
Linux: ~/.config/gcloud/application_default_credentials.json
Windows: C:\Users\%username%\AppData\Roaming\gcloud\credentials
You can delete the file, & regenerate it using commands you had mentioned in your question such as “gcloud auth default-credentials login”
We need to find where npm start is getting its credentials from. Once we figure that out, we can figure out how to change it, & understand why it’s looking there etc.
Are you able to find the config file to see where it is looking for credentials?
Is npm start the entire command? I’m not too familiar with Node JS. I’m not sure why it is trying to use Natural Language API.
You also mentioned a tutorial but I think you may have forgotten to include it in your question. Which tutorial are you referring to?

Contribute to django via github

I'm new at contributing. I made an improvement in django documentation and I want to push it to github. I follow this guide but I got the following problem on the push command git push origin ticket_xxxxx:
remote: Permission to django/django.git denied to <user>.
fatal: unable to access 'https://github.com/django/django.git/': The requested URL returned error: 403
My remote repositories are:
origin https://github.com/django/django.git (fetch)
origin https://github.com/django/django.git (push)
Any idea?
If you read the documentation carefully, you'll notice that in Setting up local repository, it leads you to clone the forked repository instead of the original django repository.
git clone git#github.com:github_nick/django.git
^^^^^^^^^^^
Instead of trying to push to django repository directly, fork django repository.
Commit, push to your forked repository. Then create pull request.