ER_ACCESS_DENIED_ERROR CloudSQL [英] ER_ACCESS_DENIED_ERROR CloudSQL

查看:211
本文介绍了ER_ACCESS_DENIED_ERROR CloudSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到这样的错误(在我的函数日志中)

I am receiving an error which looks like this (in my functions log)

拒绝用户\'varun_admin\'@\'cloudsqlproxy~84.117.112.32\' (using password: YES)',

    sqlMessage:
`\'varun_admin\'@\'cloudsqlproxy~84.117.112.32\' (using password: YES)',`
    sqlState: '28000',
 

致命:true} (84.117.112.32)被有意修改.

fatal: true } (84.117.112.32) intentionally modified.

我已经仔细检查了usernamepassword,实际上,我从工作台发出了一个请求,并且一切正常.

I have double checked my username and password, In fact, I made a request from workbench and it went fine.

这就是我创建/初始化SQL的方式

This is how I am creating/initialising my sql

const mysql = require('mysql')
const config = require('./../../config.js')


const connectionName = config.DB_CONNECTION_NAME
console.log(`Connection name: ${config.DB_CONNECTION_NAME}`)
const configSQL = {
    host: config.DB_HOST,
    user: config.DB_USER,
    password: config.DB_PASSWORD,
    database: config.DB_DATABASE
}

// Connection to cloud sql in production

if (!process.env.dev) {
    configSQL.socketPath = `/cloudsql/${connectionName}`;
}

//SQL Config
const pool = mysql.createPool(configSQL)

// Checking if it was connected sucessfully or not on server startup
pool.getConnection((err, connection) => {
    if (err) {
        console.error('error connecting: ' + err)
        return
    }
    console.log('connected as id ' + connection.threadId)
    connection.release()
    return
})

并且以下函数通常会调用以获取数据

And the following function would typically make a call to get data

const getEverythingFromTable = tableName => {
    return new Promise((resolve, reject) => {
        pool.getConnection((error, connection) => {
            if (error) return reject(error)
            const query = `SELECT * FROM ${tableName}`
            connection.query(query, (err, response) => {
                connection.destroy()
                if (err) return reject(err)
                return resolve(response)
            })
        })
    })
}

知道我可能做错了什么吗?

Any idea what I could be doing wrong?

SQL日志

更新:1

这些是我传递给Cloud SQL Config的环境值

These are the environment values I am passing to the Cloud SQL Config

(请参阅上面的代码段)

(Please refer to the code snippet above)

我的UI中的cloudSQL配置如下所示

Where my cloudSQL config in the UI looks like this

我如何调用函数/调用它们,上面的NodeJS代码.

How I am invoking functions/ calling them, the NodeJS code for it is above.

推荐答案

我实际上试图通过将实例配置更改为仅允许SSL连接来查看是否可以重现该问题,如

I actually tried to see if I could reproduce the issue by I changing my instance configurations to Allow only SSL connections, as suggested by the Enforcing SSL/TLS section of the documentation. However, it didn’t cause the issue for me

这通常不会出现问题,因为正如这篇文章中所述,来自Cloud Functions的连接由您使用 cloudsqlproxy 时的默认设置,但我必须对其进行测试,以防某些更改.

This would not usually be a problem since, as mentioned in this post, the connections from Cloud Functions are encrypted by default when you use the cloudsqlproxy, but I had to test it in case something changed.

我还尝试更改配置,以进一步限制对我的实例的访问.但是,导致我的连接失败的唯一原因是禁用了通过公共IP的连接,而仅允许通过私有IP的连接,这使得该连接甚至无法到达该实例.

I also tried changing the configuration in order to restrict the access to my instance even more. However the only thing that failed my connection was disabling the connection through the Public IP and only allowing it through the Private one, and this made so the connection did not even reach the instance.

自从您提到能够连接到工作台以来,我相信有两种可能的原因可以引起您的问题:

Since you mentioned you are able to connect with the Workbench, I believe there are 2 possible causes for your issue:

  1. 您的某些字符的编码可能存在问题 密码,只有在尝试从 env 变量.我建议您尝试使用非常基本的密码来查看 如果您得到相同的结果.
  2. 来自以下位置的连接加密可能存在问题 云功能.如果是这样,这将非常具体 到您的项目,解决此问题的最佳方法是 在 Google的问题跟踪器上打开问题,或打开支持 如果您有支持计划.
  1. There could be a problem with the encoding of some characters in your password, that only get mess up when trying to access it from the env variables. I suggest you try with a very basic password to see if you get the same result.
  2. There could be an issue with the encryption of the connection from the Cloud Function. If that is the case, this would be very specific to your project and the best way to address this issue would be to open an issue on Google’s Issue Tracker, or to open a support case, in case you have a support plan.

希望对您有帮助.

这篇关于ER_ACCESS_DENIED_ERROR CloudSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆