gatsyby-source-contentful failed with exit code 1 if the access key doesn't have a privilege to access master environment. Contentful API doesn't allow to retrieve a space information from a key doesn't have an access privilege to master. gatsby-source-contentful need a space id and the plugin already have information about a space id because spaceId on gatby-config.js is required. Hence, retrieving a space on startup is not needed.
Setup gatsby-source-contentful environment and remove the access privilege to master environment from a key you've set on gatsby-config.js on contentful admin page. Then run yarn develop
to start development.
The plugin can access to contentful data.
yarn develop
shows following errors.
Accessing your Contentful space failed.
Try setting GATSBY_CONTENTFUL_OFFLINE=true to see if we can serve from cache.Endpoint not found. Check if host and spaceId settings are correct
Used options:
spaceId: "**mom" - Check if setting is correct
accessToken: "************rQHU"
environment: "development"
host (default value): "cdn.contentful.com" - Check if setting is correct
downloadLocal (default value): false
localeFilter (default value): [Function]
forceFullSync (default value): false
System:
OS: macOS 10.15.1
CPU: (4) x64 Intel(R) Core(TM) i5-8210Y CPU @ 1.60GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.12.0 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.11.3 - /usr/local/bin/npm
Languages:
Python: 2.7.16 - /usr/local/bin/python
Browsers:
Chrome: 78.0.3904.97
Firefox: 70.0.1
Safari: 13.0.3
npmPackages:
gatsby: ^2.17.9 => 2.17.9
gatsby-image: ^2.2.30 => 2.2.30
gatsby-plugin-google-analytics: ^2.1.24 => 2.1.24
gatsby-plugin-google-fonts: ^1.0.1 => 1.0.1
gatsby-plugin-manifest: ^2.2.26 => 2.2.26
gatsby-plugin-offline: ^3.0.18 => 3.0.18
gatsby-plugin-react-helmet: ^3.1.13 => 3.1.13
gatsby-plugin-sass: ^2.1.20 => 2.1.20
gatsby-plugin-sharp: ^2.2.36 => 2.2.36
gatsby-plugin-sitemap: ^2.2.19 => 2.2.19
gatsby-source-contentful: ^2.1.55 => 2.1.55
gatsby-source-filesystem: ^2.1.35 => 2.1.35
gatsby-transformer-remark: ^2.6.32 => 2.6.32
gatsby-transformer-sharp: ^2.3.2 => 2.3.2
npmGlobalPackages:
gatsby-cli: 2.4.8
Thank you for opening this!
As the plugin uses Contentful's node API wrapper both are required:
https://github.com/contentful/contentful.js/#configuration
Hence this is not a bug/a wontfix and it's working as intended. Please provide both required configs. Thanks!
We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby!
This really needs to be documented and have a more verbose error, it was the cause of #18418 and could be the cause of many others like #18904
@jordan314, @daigok: Thanks for for providing insight into this, I was going crazy haha.
@LekoArts This is quite problematic if you for example want to use CI. I don't want to grant our testing tools master access, just to the dev environment in Contentful. The key has to be shared with the CI-provider.
@LekoArts I'm not sure how this is not a bug?
It suddenly started to be an issue at some point (between 2.1.15 and 2.1.55), without touching the contentful
package version at all.
It has probably being introduced by https://github.com/gatsbyjs/gatsby/pull/17923 on 2.1.45, where that user required the spaceId probably due building content from a multispace setup.
I'm not sure why this change has been approved so easily, as I believe the most popular scenarios is to build form a single space which - as @daigok reminded - has the space id already in the configuration.
The change is breaking builds, and the only workaround is to grant access to master which is quite a big security issue.
Shall we either:
is_multispace
new plugin config setting is set to true
(probably better).Just hit this as well. I agree that this might not be ideal for those of us wanting stricter access control. I think @gambry has something with the is_multispace
setting.
Just ran into this issue and went through a long series of WTFs before I found this thread. To me, the current behaviour is really unexpected. Having to grant access to the master
environment defeats the purpose of using environments as a means of isolation and unintended master content change prevention in the first place. This should be either documented with big caps or fixed (preferred if possible). Why exactly does it need access to the master
environment?
As the plugin uses Contentful's node API wrapper both are required:
https://github.com/contentful/contentful.js/#configuration
@LekoArts I'll admit I don't fully understand this argument. It links to a list of available config options but I can't find any requirement that mandates the provided key has to have access to the master environment. Can you please elaborate? I wonder if the documentation got updated since you linked to it.
@mareksuscak Yep - same here. We went through several cycles of debugging/troubleshooting and opened a Contentful support ticket before finding this thread.
The reason we created a new environment was to enable a third-party vendor to develop new features with out the risk of impacts to the 'master' environment. This restriction defeats the purpose...
@mareksuscak I totally agree. I was just trying to upgrade this from an older version of gatsby-source-contentful
so that I could use the locale filters and spend ages trying to figure out why it suddenly stopped working.
Also, In the same project I have some api routes that get data from contentful using the contentful package and that was working fine so I was even more confused.
Most helpful comment
Just ran into this issue and went through a long series of WTFs before I found this thread. To me, the current behaviour is really unexpected. Having to grant access to the
master
environment defeats the purpose of using environments as a means of isolation and unintended master content change prevention in the first place. This should be either documented with big caps or fixed (preferred if possible). Why exactly does it need access to themaster
environment?@LekoArts I'll admit I don't fully understand this argument. It links to a list of available config options but I can't find any requirement that mandates the provided key has to have access to the master environment. Can you please elaborate? I wonder if the documentation got updated since you linked to it.