Google cloud platform Google云CDN以bucket作为后端签署cookie

Google cloud platform Google云CDN以bucket作为后端签署cookie,google-cloud-platform,google-cloud-cdn,Google Cloud Platform,Google Cloud Cdn,作为url前缀的替代方案,我正在尝试开始工作。Google Cloud CDN是用一个后端bucket来设置的,该bucket是为标准签名URL配置和工作的 使用这些,我在nodejs(typescript)中实现了一个cookie签名函数,当与一起提供时,它会产生预期的结果 export function signCookie(urlPrefix: any, keyName: string, key: any, experation: Date): string { // Base64

作为url前缀的替代方案,我正在尝试开始工作。Google Cloud CDN是用一个后端bucket来设置的,该bucket是为标准签名URL配置和工作的

使用这些,我在nodejs(typescript)中实现了一个cookie签名函数,当与一起提供时,它会产生预期的结果

export function signCookie(urlPrefix: any, keyName: string, key: any, experation: Date): string {
    // Base64url encode the url prefix
    const urlPrefixEncoded = Buffer.from(urlPrefix)
        .toString('base64')
        .replace(/\+/g, '-')
        .replace(/\//g, '_');

    // Input to be signed
    const input = `URLPrefix=${urlPrefixEncoded}:Expires=${experation.getTime()}:KeyName=${keyName}`;

    // Create bytes from given key string.
    const keyBytes = Buffer.from(key, 'base64');

    // Use key bytes and crypto.createHmac to produce a base64 encoded signature which is then escaped to be base64url encoded.
    const signature = createHmac('sha1', keyBytes)
        .update(input)
        .digest('base64').replace(/\+/g, '-')
        .replace(/\//g, '_');

    // Adding the signature on the end if the cookie value
    const signedValue = `${input}:Signature=${signature}`;

    return signedValue;
}
然后,当我使用相同的函数为我的实际cdn实例生成签名cookie值时,我得到以下结果(键名和url前缀不是实际值):

URLPrefix=aHR0cHM6L-----------------HdhcmUuaW8v:Expires=158555646437:KeyName=my key name:Signature=2mJbbtYVclycXBGIpKzsJWuLXEA=

使用firefox开发工具创建烹饪,我在连接cookie和未连接cookie时得到以下两个结果:

看起来cookie“Cloud CDN cookie”只是通过云CDN直接传递到后端存储桶,在那里它被忽略,并且给出了标准的响应访问拒绝响应

云平台日志显示没有cdn干预

附有饼干 没有附加cookie


签名实现或cookie的创建和使用中是否有我做错的地方?

我的Google项目尚未启用签名cookie功能。另一位用户联系了支持部门,一旦他们解决了问题,我就解决了,代码没有任何更改,它就正常工作了

这是我的最后一个nodejs(typescript)签名cookie实现

function signCookie(urlPrefix: any, keyName: string, key: any, experation: Date): string {
    // Base64url encode the url prefix
    const urlPrefixEncoded = Buffer.from(urlPrefix)
        .toString('base64')
        .replace(/\+/g, '-')
        .replace(/\//g, '_');

    // Input to be signed
    const input = `URLPrefix=${urlPrefixEncoded}:Expires=${experation.getTime()}:KeyName=${keyName}`;

    // Create bytes from given key string.
    const keyBytes = Buffer.from(key, 'base64');

    // Use key bytes and crypto.createHmac to produce a base64 encoded signature which is then escaped to be base64url encoded.
    const signature = createHmac('sha1', keyBytes)
        .update(input)
        .digest('base64').replace(/\+/g, '-')
        .replace(/\//g, '_');

    // Adding the signature on the end if the cookie value
    const signedValue = `${input}:Signature=${signature}`;

    return signedValue;
}