Code Monkey home page Code Monkey logo

Comments (4)

stephenplusplus avatar stephenplusplus commented on June 24, 2024

Sorry for the trouble, and thank you for sharing what you found. I will try to reproduce.

from nodejs-storage.

stephenplusplus avatar stephenplusplus commented on June 24, 2024

Would you mind doing a fresh deploy to GCF using @google-cloud/storage@^1.5.0? I made a change to the way errors are reported when signing fails.

from nodejs-storage.

fomojola avatar fomojola commented on June 24, 2024

The issue isn't actually with the signing failing, its that from 1.4.0 to 1.5.0 the actual policy output changed. I finally buckled down and created a simple test:

var storage = require('@google-cloud/storage');
var path = require('path');
var gcs = storage({
    projectId: "test",
    keyFilename: path.join(__dirname, "key.json")
});

var options = {
    'key': "1.key",
    equals: [['$Content-Type', 'application/pdf'], ['$success_action_status','200']],
    successStatus: '200',
    expires: '2018-12-01T06:31:42.096Z',
    contentLengthRange: {
        min: 0,
        max: 20000000
    },
};
var file = gcs.bucket("test").file("1.key");
file.getSignedPolicy(options).then(function(val){
    console.log(val);
});

If you copy this code into a directory and call it test.js, and then copy a private key JSON file (downloaded from the google cloud console) into the same directory with the filename key.json, you can do the following to see the change:

[~/projects/bug] npm install @google-cloud/[email protected]
+ @google-cloud/[email protected]
added 1 package and updated 1 package in 3.088s
[~/projects/bug] node test.js 
[ { string: '{"expiration":"2018-12-01T06:31:42.096Z","conditions":[["eq","$key","1.key"],{"bucket":"test"},["eq","$Content-Type","application/pdf"],["eq","$success_action_status","200"],{"success_action_status":"200"},["content-length-range",0,20000000]]}',
    base64: 'eyJleHBpcmF0aW9uIjoiMjAxOC0xMi0wMVQwNjozMTo0Mi4wOTZaIiwiY29uZGl0aW9ucyI6W1siZXEiLCIka2V5IiwiMS5rZXkiXSx7ImJ1Y2tldCI6InRlc3QifSxbImVxIiwiJENvbnRlbnQtVHlwZSIsImFwcGxpY2F0aW9uL3BkZiJdLFsiZXEiLCIkc3VjY2Vzc19hY3Rpb25fc3RhdHVzIiwiMjAwIl0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDAifSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwwLDIwMDAwMDAwXV19',
    signature: 'fdjZmFVMjqptIC9k4RFQdsijia8agVZYELpUtr7WCxxaxXzJvSrp/w+ECU7Kke9+Y/W5TxbB/ybhjZPrmA7g0m1WVVh5z+KYixz1CPs7P1ESKVuoH86FSXntYkqIoKgH8b3WKpFGkez9nI1ZYOV7oIvHpYWtFvvkkr61Pk1P/PTD5wXIUF+edWRtYbp0oA7xkhxzldMDk2xy6EkCF8obdqL/utrBi8V9yD2M56uOAhZah/R03ybJqMFxwWlZhM/0Usiq7qbp6lH8AfHYRktYcAtvl84ssgUuEzxSL0dOWj6LNalmFjSpN6TBd8It+Ma7ohqSQZZ2C0TQ9J7Yo7fzqg==' } ]
[~/projects/bug] npm install @google-cloud/[email protected]
+ @google-cloud/[email protected]
added 5 packages and updated 1 package in 4.706s
[~/projects/bug] node test.js 
[ { string: '{"expiration":"2018-12-01T06:31:42.096Z","conditions":[["eq","$key","1.key"],{"bucket":"test"},["eq","$Content-Type","application/pdf"],["eq","$success_action_status","200"],{"success_action_status":"200"},["content-length-range",0,20000000]]}',
    base64: 'eyJleHBpcmF0aW9uIjoiMjAxOC0xMi0wMVQwNjozMTo0Mi4wOTZaIiwiY29uZGl0aW9ucyI6W1siZXEiLCIka2V5IiwiMS5rZXkiXSx7ImJ1Y2tldCI6InRlc3QifSxbImVxIiwiJENvbnRlbnQtVHlwZSIsImFwcGxpY2F0aW9uL3BkZiJdLFsiZXEiLCIkc3VjY2Vzc19hY3Rpb25fc3RhdHVzIiwiMjAwIl0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDAifSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwwLDIwMDAwMDAwXV19',
    signature: 'hz/C3zdCAQfAJYCsPJ/7mC9R3PwBIDXHv7N6+eTDPNBKrdri8d89aU/Pt6DDaMhkiXgjnGx4BNLKGj6//Zrkv1vLg0PYKIky4r9u7XS6Pg+NnY2TzShmZVzuJ4sCyzcEZeJTKKIWrn1BgQJvrzeDs0ZXghJBEpknO4dMjrzkl7Op6LS/Prl1Cmv9xZ7GDY4EHleq210UR16E1s4PWWhGwAwuJT6FTJM21zQPrgb+BhAJvq8iDOcPS0Cc4HFER7slkyCB847FyezDEEP4/x2H9XoHguFZuuUDBs3IjwAvpQbIOqU2qEUvGYB4KL8XuKk+tB78pQuulrWl3F/CySyGlw==' } ]

You'll notice that for the exact same policy document and base64 data, the signature is different going from 1.4.0 to 1.5.0: there is no error, just a different signature value that isn't accepted by the cloud storage servers.

from nodejs-storage.

stephenplusplus avatar stephenplusplus commented on June 24, 2024

Thanks for that. Indeed, we changed how we were generating the signed policy. I have sent a fix in #99.

from nodejs-storage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.