GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — makePrivate not working? · Issue #763 · googleapis/google-cloud-node

makePrivate not working? #763

New issue
Copy link
New issue
Copy link
Closed
Closed
makePrivate not working?#763
Copy link
Assignees
stephenplusplus
Labels
api: storageIssues related to the Cloud Storage API.

Description

@MKHenson
MKHenson
opened on Jul 30, 2015
Issue body actions

Hi guys

I think I might have stumbled on a bug. I am running a nodejs server using the gcloud version 0.16.0. When I upload a file and access said file through the URL:

https://storage.googleapis.com/bucketID/fileID

I get a 403 status saying I dont have permission. Which is correct. So in node, I call

file.makePublic(function(err, api){})

and when I access the URL now it gives me a 200 code - so far so good.

If however I want to revert the file back to private:

file.makePrivate(function(err){}) 

The function goes through fine - there are no errors - however the object remains publicly available. The http code is still 200. Is this a bug or have I done something wrong here?

Activity

  1. stephenplusplus commented on Jul 30, 2015

    @stephenplusplus
    stephenplusplus
    on Jul 30, 2015
    Contributor
    More actions

    Thanks for reporting!

    I get a 302 status saying I dont have permission.

    Are you sure it's not a 403?

    I've been getting the expected results with the following code:

    var file = bucket.file('file.txt');
    
    var writeStream = file.createWriteStream();
    writeStream.end('hi');
    
    writeStream.on('complete', function() {
      // 403
      file.makePublic(function() {
        // 200
        file.makePrivate(function() {
          // 403
        });
      });
    });

    We also have some tests that seem to cover the case well: https://github.com/GoogleCloudPlatform/gcloud-node/blob/e4fdb2d118ba5098731ccdff74d75c5aa2f69908/system-test/storage.js#L358-382

    Pinging @jgeewax in case he can think of anything.

  2. stephenplusplus
    added
    api: storageIssues related to the Cloud Storage API.
    on Jul 30, 2015
  3. MKHenson commented on Jul 30, 2015

    @MKHenson
    MKHenson
    on Jul 30, 2015
    Author
    More actions

    Hi stephenplusplus, sorry yes I meant 403. Weird... I pretty much have the exact same code. Gonna see if I can re-create it some other way

  4. MKHenson commented on Jul 30, 2015

    @MKHenson
    MKHenson
    on Jul 30, 2015
    Author
    More actions

    It seems that the file does eventually become private - but takes some time before the change is propagated. In my code I have 2 functions that are called to make the file public and private:

    // In the make private function
    var bucket = that._gcs.bucket(file.bucketId);
    var rawFile = bucket.file(file.identifier);
    rawFile.makePrivate({ strict: true }, function (err)
    {
        if (err)
            return reject(err);
    
        // other code here...
    });
    
    
    // In the make pubic function
    var bucket = that._gcs.bucket(file.bucketId);
    var rawFile = bucket.file(file.identifier);
    rawFile.makePublic( function (err, api)
    {
        if (err)
            return reject(err);
    
        // other code here...
    });
    

    The file is just a basic image which was uploaded like so

    var stream = rawFile.createWriteStream();
    
    // Pipe the file to the bucket
    stream.on("error", function (err: Error)
    {
          // reject upload
    
    }).on('complete', function ()
    {
          // Updates to DB
    })
    

    So is it perhaps just that it takes time before the changes are aparent? (I was testing the raw file in chrome with cache disabled)

  5. jgeewax commented on Jul 30, 2015

    @jgeewax
    jgeewax
    on Jul 30, 2015
    Contributor
    More actions

    It's definitely possible that the ACLs do not propagate immediately. If that's the case, you'd have some lag after the makePrivate() call and getting the expected 403.

  6. stephenplusplus commented on Jul 30, 2015

    @stephenplusplus
    stephenplusplus
    on Jul 30, 2015
    Contributor
    More actions

    I've been playing with this for a bit, and at first it seemed to work (when I made my first comment here), but now I'm struggling:

    var file = bucket.file('file.txt');
    var url = 'https://storage.googleapis.com/' + bucket.name + '/' + file.name;
    
    var writeStream = file.createWriteStream();
    writeStream.end('hi');
    
    writeStream.on('complete', function() {
      async.series([
        confirmFileIsPrivate,
    
        wait(1500),
        file.makePublic.bind(file),
        confirmFileIsPublic,
    
        wait(1500),
        file.makePrivate.bind(file),
    
        wait(1500),
        confirmFileIsPrivate // fails. statusCode is still 200
      ], function(err) {
        assert.ifError(err);
        file.delete(done);
      });
    });
    
    function wait(ms) {
      return function(next) {
        setTimeout(next, ms);
      };
    }
    
    function confirmFileIsPublic(callback) {
      request(url, function(err, resp) {
        assert.ifError(err);
        assert.strictEqual(resp.statusCode, 200);
        callback();
      });
    }
    
    function confirmFileIsPrivate(callback) {
      request(url, function(err, resp) {
        assert.ifError(err);
        assert.strictEqual(resp.statusCode, 403);
        callback();
      });
    }

    I've tried different delays as well as confirming the statusCode with curl.

    FWIW, at one point during testing, I was convinced it was a backend race condition of sorts, where the first request to make public or private might still be processing while the second request is made. The API returns 200 for both requests, but then it's a race to see which request completes first. Anyway, I haven't been able to reproduce any success conditions now, so I'm not sure what the issue might be.

    If anyone wants to play around with the test code above, please feel free and let me know if you can plug in the right variables to make it work, or catch something wrong in how I'm testing.

  7. stephenplusplus commented on Sep 17, 2015

    @stephenplusplus
    stephenplusplus
    on Sep 17, 2015
    Contributor
    More actions

    My research was hitting anomalies thanks to getting a cached response from the storage server. This updated code succeeds:

    var file = bucket.file('file.txt.' + Date.now());
    
    var writeStream = file.createWriteStream();
    writeStream.end('hi');
    
    writeStream.on('finish', function() {
      async.series([
        confirmStatus(403),
    
        file.makePublic.bind(file),
        confirmStatus(200),
    
        file.makePrivate.bind(file),
        confirmStatus(403)
      ], function(err) {
        assert.ifError(err);
        file.delete(console.log);
      });
    });
    
    function confirmStatus(expectedStatus) {
      return function(next) {
        request({
          uri: 'https://storage.googleapis.com/' + bucket.name + '/' + file.name,
          qs: {
            cacheBuster: Date.now()
          }
        }, function(err, resp) {
          if (err || resp.statusCode !== expectedStatus) {
            next(err || new Error('Got status code: ' + resp.statusCode));
            return;
          }
    
          next();
        });
      };
    }

    Based on your last comment @MKHenson, I think this is resolved-- the backend can just take a bit to process sometimes? I'm going to close but feel to re-open if I'm mistaken.

  8. stephenplusplus
    closed this as completedon Sep 17, 2015
  9. JustinBeckwith
    assigned
    stephenplusplus
    on Feb 1, 2021
  10. sofisl
    added a commit that references this issue on Nov 9, 2022

    chore(main): release 4.1.1 (#763)

    c936d5f
  11. sofisl
    added 3 commits that reference this issue on Jan 17, 2023

    chore(deps): update dependency null-loader to v4 (#763)

    ee5fecf

    chore(nodejs): remove api-extractor dependencies (#763)

    4af6044

    chore(nodejs): remove api-extractor dependencies (#763)

    5f42152
  12. miguelvelezsa
    added 3 commits that reference this issue on Jul 23, 2025

    fix(deps): update dependency google-auth-library to v6 (#763)

    f2045e8

    chore: release 2.0.1 (#766)

    de10118

    chore: update .eslintignore (#772)

    6b57794
  13. GautamSharda
    added 3 commits that reference this issue on Jan 14, 2026

    chore(main): release 5.2.0 (#763)

    951b3f0

    chore(main): release 5.2.0 (#763)

    503bb6e

    chore(main): release 5.2.0 (#763)

    028a786
  14. miguelvelezsa
    added a commit that references this issue on Jan 28, 2026

    chore(deps): update dependency webpack-cli to v4 (#763)

    8f71e7d
  15. GautamSharda
    added 2 commits that reference this issue on Feb 2, 2026

    chore(main): release 5.2.0 (#763)

    f17f197

    chore(main): release 5.2.0 (#763)

    3da755b
  16. sofisl
    added a commit that references this issue on Feb 5, 2026

    chore(deps): update dependency webpack-cli to v4 (#763)

    2e3e46d
  17. sofisl
    added a commit that references this issue on Feb 17, 2026

    chore(deps): update dependency webpack-cli to v4 (#763)

    40942d6
  18. GautamSharda
    added 2 commits that reference this issue on Mar 5, 2026

    fix(deps): update dependency @google-cloud/promisify to v2 (#763)

    40f8b9b

    build: have Kokoro grab service account credentials from secret that …

    221d974
  19. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    chore: delete Node 8 presubmit tests (#763)

    f8a27f1

    chore: delete Node 8 presubmit tests (#763)

    027e037
  20. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    chore: delete Node 8 presubmit tests (#763)

    5d2eb2f
  21. thiyaguk09
    added a commit that references this issue on May 5, 2026

    chore: delete Node 8 presubmit tests (googleapis#763)

    a759b39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @stephenplusplus
    stephenplusplus

Labels

api: storageIssues related to the Cloud Storage API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.