Automate DVC authentication when using github actions - authentication

I'm using GitHub Actions to run some tests on every push and I need DVC. I'm trying to make this work with the runs-on: ubuntu-latest option but when I try to run it, the action get's stuck because it requires manual authentication. Is there a way to go around this and automate the authentication ?

I figured out that in order for this to work, I had to switch to using a service account.

I had the same issue. Here are the steps I used to setup a Google Service Account with DVC, Google Drive and Github Actions.
Setup a google cloud platform service account
A google cloud platform service account "is a special kind of account used by an application or compute workload, such as a Compute Engine virtual machine (VM) instance, rather than a person. A service account is identified by its email address, which is unique to the account." In this case, the service account for your app to access Google Drive.
Go to the Google API Console
Select or Create a project for DVC remote connections.
Enable the Google Drive API by clicking the ENABLE button
Go to the Google API Crediential page
Click on the + Create Credentials button and then select Service Account.
Enter a service account name (such as gdrive-api) and a some description (such as "Allows access to the google drive api") then click on the Create and continue button.
Click continue at the "Grant this service account access to the project (optional)" section: No need to add any accesses.
Click Done at the "Grant users access to this service account (optional)". Again, no need to grant any additional accesses.
Go to Service Accounts. You'll see a list of all service accounts for the your GCP project and click on the service account you just created.
Click on key --> add key --> Create new key and
In the popup window that appears, select JSON as key type, click the Create button. A JSON file of the key you created will download.
Share access to the Google Drive folder where the DVC repo will live
Still on Google Cloud Platform,
Go in IAM --> Service Accounts and click on the service account name you created in the previous section
Copy and paste the email associated to this service account. It should have a form service_account_name#project_id.iam.gserviceaccount.com
Move to Google Drive and share the drive folder where the DVC repo will live with the service account email defined in the last step.
Set DVC config to use a google service account
On your local machine, modify the DVC project config file by typing the following commands. Change my_remote with your actual DVC remote name.
dvc remote add --default my_remote gdrive://your_folder_hash
dvc remote modify my_remote gdrive_use_service_account true
dvc remote modify my_remote --local gdrive_service_account_json_file_path path/to/file.json
This will modify the .dvc/config and .dvc/config.local files in your project.
Run the command dvc push. If you see no error message, you are done with this step.
Push your code to origin on Github
Setup a Repository Secret
In your Github repo, go to Settings -> Secrets and Variables -> Actions
Click on the New repository secret button.
Name the secret to whatever is meaningful to you.
Copy and paste the JSON file content you downloaded in the previous section to the Secret* text box.
Click the Add Secret button
Setup a Github action
To your Github action yaml file, add the following (make sure to change the YOUR_REPO_SECRET_NAME to the name of the repo secret you created in the previous step.
- uses: iterative/setup-dvc#v1
- name: Pull data with DVC
env:
GDRIVE_CREDENTIALS_DATA: ${{ secrets.YOUR_REPO_SECRET_NAME }}
run: |
dvc pull
Commit this change and run the Github action!
References
How to Setup a Google Drive DVC Remote

Related

Google Analytics and BigQuery link issue

I am getting an error while linking Bigquery to Google analytics" We encountered a permission error for the selected BigQuery project. Please ensure that the service account has edit permissions on the project and try again. See the linking instructions for more information.
I want to know how to set up service account on cloud console?
Your error is usually related to two types of permissions, one is the Service Account that you use to access BigQuery and the other is the email address you use to login to Google Analytics.
Service Account
In order to create a new service account, you should follow the steps described here. So, in IAM & Admin > Service Accounts > Create Service account. Then, 1: give the service account details, 2: Grant this service account access to project(select the roles) and 3: Grant users access to this service account(add users)
In your case make sure that, you have to add this service account analytics-processing-dev#system.gserviceaccount.com to your project. In order to don so, you have to navigate to IAM & Admin > IAM. Then, click in the top right corner ADD, copy and pate the service account and Select a role: Project > Editor, link for the documentation.
Permissions in Google Analytics
The email you use to login with Google Analytics must to have OWNER access to the BigQuery Project and Edit permission for the Analytics property that includes the view you want to link, here.
Therefore, after performing these actions, you will be able to link BigQuery with Google Analytics.
Attention: In addition, I must mention that you first have to ensure you enabled Billing for your project, here.

Android-quick start app with google drive is not working

I am trying to upload an image using quick start tutorial to google drive initially my app starts and asks to choose account but when I select an account it keeps asking again and again.
As shown in the code, no account name is passed. Try setting useDefaultAccount() method which will specify that the default account should be used when connecting to services. Otherwise, use clearDefaultAccountAndReconnect() method if you prefer setting up multiple accounts. This method will clear the account selected and will prompt the user to pick an account before reconnecting.
See GoogleApiClient for more information regarding sign_in.
In addition to that, see also installation and configuration of the Google Play services SDK regarding creation of credentials.
If you haven't done so, check credentials created for your project. Here are the steps:
Open the Credentials page in the API Console.
Follow these steps if your application needs to submit authorized
requests:
a. Click Create credentials > OAuth client ID.
b. Select Android.
c. In the Package name field, enter your Android app's package name.
d. Paste the SHA1 fingerprint into the form where requested.
e. Click Create.
Otherwise, follow the steps below, which are for applications that only need to make unauthorized API calls:
a. Click Create credentials > API key.
b. Select Android key.
c. Paste the SHA1 fingerprint into the form where requested.
d. Type your Android app's package name into the form where requested.
e. Click Create.

Google Drive Android: Error signing in the specified account. Please choose a different account

I am implementing the google drive use google play services.
I enable drive Api and Drive SDK from api console, and implemented configuration settings for Drive SDK, But when I try to login from my application, I get the following error,
Error signing in the specified account. Please choose a different account,
I add another account but facing the same error,
I did not know what is the problem? did I have to add the test users? but I did not find any place to test users.
In authentication section (https://developers.google.com/drive/web/enable-sdk#drive_integration). I found . In order to authenticate Drive users with the user info service, you must manually enter the following two scopes:
email
profile
But scope section only allow to enter the url and not the email and profile.
In the Google Developers Console, the package name must be the same as the Android app's package name in your android studio.
If you enter the wrong name, you may get this error message.

How to publish google apps script to cloud for public?

I have a apps script that uses bigquery service to fetch data from my bigquery account and builds visualizations/tables etc. I publish the app with following options
Execute App as: User accessing web app
Who has access to this app: Anyone
When I open the link (one ending in exec not dev) in chrome incognito, I expect it to show the web app but it asks for google credentials.
When I entering credentials of my other (different from the one hosting the project) account, I get a permissions error.
I added this other account from my primary one under permissions option of google console - even that wasn't enough.
I had to create a dummy project as this other user to accept the invitation from my primary account. After that the app showed up on this other account.
My question is, how do I publish my app for the consumers (even public) of this info without them having to create dummy project/accept my invite etc?
Thanks
You have two errors:
1) Publish to run as you not the user, and2) make it anonymous access. *
People might consume your daily/per second quotas thou.
(*) anonymous access option might not be present if the google apps administrator disabled anonymous sharing in the console.

gcutil to add new user to project

Hi i have a project in my google cloud engine and i'm having ubunutu laptop i have set gcutil
in my laptop . I need another user to login to same project he is using windows machine i have set up gcutill via cygwin
But the problem is i have create another user to compute engine .
Please guide me to set the second user to login into the same instance of project and both should have equal privileges on editing the project. Please ask me if you need more information.
To add a new user to your project, visit https://cloud.google.com/console. Click on Permissions in the left-hand column. This page allows you to add additional users to your project. Click the Add User button, enter their email address (it should be a Google account) and to give them exactly the same permissions as the person who created the project, choose Owner for the permissions.
Now that user can authenticate gcutil using their account.