I have a (non-admin) account on one GCP project.
When I start the Dataproc cluster, GCP spins up 3 VMs. When I try to access one of the VM via SSH (in browser) I get the following error:
I tried to add recommended permissions, but I cannot add the iam.serviceAccounts.actAs permission.
Any idea how to solve this? I read through the GCP documentation, but I just cannot find the solution for this. I have the following roles associated with my account:
If from console you want to click the "SSH" button next to an instance but face this issue, you can grant the Service Account User role instead of Editor, and it should resolve this.
If you're using OS Login, you may need the Compute OS Login role as well, but SA user should work.
If you're using IAP, you may need the IAP-secured Tunnel User role (or roles/iap.tunnelResourceAccessor in CLI)
Before:
After adding Service Account User role:
If you want to access remotely, use a bastion and Cloud IAP tunnel. Here is an example setup/teardown (NAT and router optional if you want to configure your bastion or install packages)
In the end, we managed to solve it by granting users the Editor permission on Compute Engine default service account. Not sure it is the right way but it seems to work.
I believe the latest documentation on Compute Engine SSH access is here: https://cloud.google.com/compute/docs/instances/managing-instance-access
It seems that you have to enable OS Login on the specific instance(s) you want to SSH into.
Adding an ID under a role for a specific instance somehow did not work for us
However, when the same ID was assigned the same role under IAM, it worked
Official docs: https://cloud.google.com/compute/docs/instances/access-overview
For OS Login https://cloud.google.com/compute/docs/oslogin/set-up-oslogin :
roles/compute.osLogin, which doesn't grant administrator permissions
roles/compute.osAdminLogin, which grants administrator permissions
If you use IAP additionally you have to add: roles/iap.tunnelResourceAccessor, see https://cloud.google.com/iap/docs/managing-access
Related
I got an developer intern. I need him to access GCP paid VM Instance I created so he can start developing. He should have root access through sudo, and preferably his own username linux account so we can see his files when he clones repo's,installs services,etc.
He should not: have access to modify instance, no access to change discs or instance size, no access to any other resource. Just ssh and root inside a vm.
His account is under his personal email abc..#gmail.com
What exact permissions do I need to give him?
a) I used the default service account, but I could switch it to project specific service account that will soon also run cloud functions.
b) For google employees, there should really be a guide/tour for "grant access" that allows people who have less then 10 vm instances follow it to grant access properly without delay or compromising security. He is unable to do paid work :(.
Related:
52756755(why does he need compute admin role for a developer, I need him only to develop and not maintain the instance)
62925708 (why does the user need service account role? He does not need to be creating paid instances)
49384500 (You do not have sufficient permissions to ssh into this instance)
do not have permission to ssh into this instance(
You do not have sufficient permissions to SSH into this instance. You need one of compute.instances.setMetadata, compute.projects.setCommonInstanceMetadata or compute.instances.osLogin (with OsLogin enabled) and iam.serviceAccounts.actAs.
If the person has #gmail.com domain then he is an external user and needs to be given external user permission.
Go to IAM & Admin -> From the Project menu select All and click the top organization:
Add the Compute OS Login External User
Now under the project Add the following:
Add Project - Viewer
Add Compute Engine - Service Account User
[optional]Add Compute Engine -Compute View
**although the Compute View is optional to just ssh, but it does help the developer/programmer/intern to know what they are running and recommend configuration changes when program is ready for golive.
And finally we need to give permission at the instance level. So go to Compute Engine -> VM Instances -> Permissions -> Add Principal -> "Compute OS Admin Login" if you want them to use sudo or if just a regular user "Compute OS Login"
Open the instance, click edit and enable OS-Login under Metadata. Add the following
Key: enable-oslogin
Value: TRUE
Stop and start the instance. You need it for permission to take effect. During troubleshooting none of this worked until we restarted the instance, and magically fixed.
If you need to manage user access to your Linux VM instances, you can use one of the following methods:
OS Login
Managing SSH keys in metadata
Temporarily grant a user access to an instance
To give a user the ability to connect to a VM instance using SSH
without granting them the ability to manage Compute Engine resources,
add the user's public key to the project, or add a user's public key
to a specific instance. Using this method, you can avoid adding a user
as a project member, while still granting them access to specific
instances.
More information about granting users SSH to VM instances can be found here.
Regarding your question about the roles required and why, here is more information about granting access to an organization using Cloud IAM roles.
More information about Access control for users in Cloud compute Engine here.
About roles and permissions
If you need your employee to be able to see the project you need to grant the access to the project according to your needs.
The basic roles are owner, editor and viewer. Here you will find a more detailed explanation about roles and permissions using Cloud IAM to control the access for your project.
And in this page you will find a complete list of the roles and permissions included in Cloud compute engine.
On the other hand in this guide about setup OS login, the roles and permission required to complete the process are included. OS login is an option suitable to resolve your issue.
How may you enable a single IAM user to access a single VM via SSH or cloudshell?
I've tried every variation of Compute Admin permissions, along with a condition on the resource name (matching the VM name) and they are not adequate; i.e. - the users connection is always unexpectedly closed.
Cloud shell is also not available to the user.
The only way the user can access either resources is if they are granted the Owner role.
Here is a similar question, duplicate it if you want but it is unanswered (1 answer does not solve the problem), SSH into a VM instance managed by an Instance Group in GCP without Owner IAM permission on the project
You can try OS login. OS Login simplifies SSH access management by linking your Linux user account to your Google identity. Administrators can easily manage access to instances at either an instance or project level by setting IAM permissions.
OS Login provides the following benefits:
Automatic Linux account lifecycle management
Fine grained authorization using Google IAM - Project and instance-level administrators can use IAM to grant SSH access to a
user's Google identity without granting a broader set of privileges.
For example, you can grant a user permissions to log into the system,
but not the ability to run commands such as sudo. Google checks these
permissions to determine whether a user can log into a VM instance.
Automatic permission updates
Ability to import existing Linux accounts
How to Setting up OS Login
You can apply the metadata values to your projects or VMs by using one
of the following options:
Option 1: Set enable-oslogin in project-wide metadata so that it applies to all the instances in your project.
In the Google Cloud Console, go to the Metadata page.
Click Edit.
Add a metadata entry, setting the key to enable-oslogin and the value to TRUE. Alternatively, set the value to FALSE to disable the
feature.
Click Save to apply the changes.
Option 2: Set enable-oslogin in the instance metadata of an existing instance.
In the Google Cloud Console, go to the VM instances page.
Click the name of the instance that you want to enable OS Login on.
On the instance details page, click Edit.
Under Custom metadata, add a metadata entry, setting the key to enable-oslogin and the value to TRUE. Alternatively, set the value to
FALSE to disable OS Login on the instance.
Option 3: Enable OS Login when you create an instance.
In the Cloud Console, go to the Create an instance page.
Expand Networking, disks, security, management, sole tenancy to reveal additional configuration options.
Expand the Security section.
Expand the Manage access section.
Select Control VM access through IAM permissions.
To create the VM, click Create.
If you want to use 2-step verification, please follow this link:
Setting up OS Login with 2-step verification.
You can try to grant following permissions to use IAP TCP forwarding
roles/iap.tunnelResourceAccessor
roles/compute.instanceAdmin.v1
https://cloud.google.com/iap/docs/using-tcp-forwarding
I want to automate the creation of development servers within my org's GCP account that are tied to an individual developer.
I intend to script the copying of relevant credentials (think crypto key for GitHub). How do I lockdown the VM so that only a single user can access it. GCP has options like block-project-ssh-keys but we've found that all users are still able to login using gcloud compute ssh.
I fear this may require a really complex IAM configuration.
Is there an easy way to accomplish this? (IAM or otherwise)
Has anyone seen a project that has automated this or something similar to this? (IAM provisioning of a new tag/group/etc. using a script when a new user joins the org)
Enable OS Login on the project, ideally by using an organizational policy constraint. OS Login automatically disables metadata-based SSH keys.
Grant OS Login roles individually per VM and user so that each user can only login to their own VM.
Either don't attach service accounts to the VMs at all, or create dedicated service accounts per VM. Then grant users the Service Account user role on "their" service account only.
Don't grant any Compute* roles beyond Compute Viewer on the project. In particular, don't grant Compute Admin or Compute Instance Admin, or any other role that lets users modify instance metadata (because that would let them alter startup and shutdown scripts).
Optionally:
Grant the users Compute Viewer on the project. That ensures that they can list VMs in the Cloud Console.
Only allow SSH access via IAP TCP forwarding, and grant the IAP-secured tunnel user role on a per-VM, per-user basis.
In my environment, I have an AI Platform Notebooks instance for which I have configured single user access only. However, I am not able to SSH into it.
I have tried to make it work by granting the appropriate Cloud IAM roles. I granted both iam/serviceAccountUser and iam/Project Editor roles to a service account used for the instance. Since the instance does not have an external IP address, I have also granted iam/IAP Tunnel User role.
When the AI Platform Notebooks is created using the default service account, it is working fine. Obviously, I must be missing something granular. Is the restriction applied to the single user working, or what could be causing this?
We have new IAM user permissions when you enable Notebooks API.
Enable Notebooks API
When you create a new Notebook,
a) From UI:
Create a new Notebook > Customize > Permission > Single User Mode.
b) If using gcloud compute command: Make sure you use the following Metadata values are set:
proxy-mode: mail
proxy-user-mail: user#domain.com
c) If using gcloud notebooks beta instances create command passing metadata using --metadata option:
proxy-mode=mail, proxy-user-mail=user#domain.com
Grant user AI Notebooks IAM permissions on the IAM page.
In this case could be Notebooks Admin or Notebooks Runner.
Once that is done,
Verify your Metadata and make sure:
enable-oslogin is set to TRUE
For SSH Access:
Check:
https://cloud.google.com/compute/docs/instances/managing-instance-access#grant-iam-roles
https://cloud.google.com/compute/docs/oslogin/troubleshoot-os-login#checking_if_os_login_is_enabled
Note: I remember I needed to logout and login back before I was able to see the SSH button enabled and use Chrome.
I can go eb ssh.
I can't though work out what the ssh command on it's own would be.
I want my colleague to be able to ssh in.
They have an AWS account.
What page in the doco should I be following ?.
edit:
I actually want them to be able to go eb deploy so basically how do you set up eb to use someone else's system ?
AWS allows you to delegate access to a user in another AWS account so that he can work with your resources. See IAM Roles, Delegating Access Across Accounts, and IAM Roles with Elastic Beanstalk.
Alternatively, you could simply create an IAM user in your account with the relevant permissions and then give those credentials to your colleague. Roles and cross-account access are generally the preferred method, however.