Google Appengine(Flex)+云SQL auth代理—使用不同的帐户进行部署和访问云SQL

发布于 2025-01-30 14:56:56 字数 1649 浏览 4 评论 0原文

我正在使用Maven插件部署到Appengine。我需要登录以使其能够部署服务。我需要登录到Gcloud,以便能够使用云SQL auth代理。现在,我看不到将Deployer帐户分别设置为Cloud SQL Auth代理帐户的任何方法,这意味着我必须使用相同的帐户,该帐户从部署开始并以“ Cloud SQL Connector/实例用户”结尾。这是设计缺陷吗?我想念什么吗?

所需状态:

  1. Appengine Flex中的手动缩放服务(基本上是单身,旧版Monolith应用程序)
  2. 云SQL SQL SQL PostgreSQL实例
  3. 单独的服务帐户,用于部署的单独服务帐户,用于.json键
  4. 单独的服务帐户(IAM),用于云SQL sql auth proxy with .json key

更新。

<beans profile="appengine">
    <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
        <property name="poolName" value="springHikariCP" />
        <property name="connectionTestQuery" value="SELECT 1" />
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="connectionTimeout" value="600000"/>
        <property name="jdbcUrl" value="${db.url}" />
        <property name="username" value="${db.username}"/>
        <property name="password" value="${db.password}"/>
        <property name="dataSourceProperties">
            <props>
                <prop key="sslmode">disable</prop>
            </props>
        </property>
    </bean>

env_variables:
  JAVA_OPTS: >-
    -Ddb.username=postgres -Ddb.password=postgres-password
    -Ddb.url=jdbc:postgresql://127.0.0.1:3306/dbname?cloudSqlInstance=project:location:instance&socketFactory=com.google.cloud.sql.postgres.SocketFactory

beta_settings:
  #tcp sockets:
  cloud_sql_instances: project:location:instance=tcp:3306

I'm using maven plugin to deploy to AppEngine. I need to be logged in to gloud to be able to deploy services. I need to be logged in to gcloud to be able to use Cloud SQL Auth Proxy also. Now I don't see any way to set deployer account separately to Cloud SQL Auth Proxy account which means I have to use the same account which has broad privileges starting from deployment and ending with 'Cloud SQL Connector/Instance User'. Is it a design flaw? Did I miss something?

Desired state:

  1. Manually scaled service in AppEngine Flex (basically a singleton, legacy monolith app)
  2. Cloud SQL PostgreSQL instance
  3. Separate service account for deployment with .json key
  4. Separate service account (IAM) for Cloud SQL Auth Proxy with .json key

UPDATE.

Temporarily solved by this config:

spring-context.xml

<beans profile="appengine">
    <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
        <property name="poolName" value="springHikariCP" />
        <property name="connectionTestQuery" value="SELECT 1" />
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="connectionTimeout" value="600000"/>
        <property name="jdbcUrl" value="${db.url}" />
        <property name="username" value="${db.username}"/>
        <property name="password" value="${db.password}"/>
        <property name="dataSourceProperties">
            <props>
                <prop key="sslmode">disable</prop>
            </props>
        </property>
    </bean>

app.yaml

env_variables:
  JAVA_OPTS: >-
    -Ddb.username=postgres -Ddb.password=postgres-password
    -Ddb.url=jdbc:postgresql://127.0.0.1:3306/dbname?cloudSqlInstance=project:location:instance&socketFactory=com.google.cloud.sql.postgres.SocketFactory

beta_settings:
  #tcp sockets:
  cloud_sql_instances: project:location:instance=tcp:3306

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素手挽清风 2025-02-06 14:56:56

我认为这里有一些事情混淆了,帐户使用用于部署服务与该服务是由部署的帐户。这是两件事。

该帐户已登录到gcloud and 用于部署您的应用程序引擎服务(即具有运行gcloud app exploy exploy> deploy>的帐户的帐户)不必与一个相同这具有连接到云SQL的权限。

但是,由部署并由应用程序引擎(应用引擎默认服务帐户或自定义服务帐户)使用的服务帐户将是相同的服务帐户,以对您的云SQL实例进行身份验证。

您可以通过使用应用程序引擎默认服务帐户提供一个自定义服务帐户来范围范围范围范围,仅向您的应用程序所需的权限。这样,您可以授予cloud SQL客户端云SQL实例用户在其顶部角色,并且没有广泛的editor权限。

有关更多详细信息,请参见:“ nofollow noreferrer”>

I think a few things are being confused here, the account used to deploy the service vs. the account that the service is deployed with. These are two different things.

The account logged into gcloud and used to deploy your app engine service (i.e. the account with the permissions to run gcloud app deploy) does not have to be the same as the one that has the permissions to connect to Cloud SQL.

However, service account that is deployed with and used by App Engine (app engine default service account or custom service account) will and should be the same service account to authenticate to your Cloud SQL instance .

You can scope down the permissions used by App Engine by providing a custom service account over using the App Engine Default service account to only those that are required by your application. That way you can grant the Cloud SQL Client and Cloud SQL Instance User roles on top of it and not have the broad Editor permissions.

For more details see: Connect Cloud SQL from App Engine Flex

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文