cloudflare / cloudflare/serverless-cloudflare-workers
Authentication Error When Deploying Cloudflare Worker with Valid Credentials
- Dominant language
- JavaScript
- Stars
- 180
- Forks
- 34
- PR merge metrics
- No merged PRs in 30d
Description
### Title: Authentication Error When Deploying Cloudflare Worker with Valid Credentials
#### Description:
I am encountering an authentication error when attempting to deploy a Cloudflare Worker using the Serverless Framework with the `serverless-cloudflare-workers` plugin. The error occurs despite the fact that the credentials are valid and have been successfully tested with a direct `curl` request to the Cloudflare API.
Environment variables were defined following the [documentation](https://www.serverless.com/framework/docs/providers/cloudflare/guide/installation) guideline
```bash
export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE
export CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL
```
#### Error Message:
```bash
Error:
'[{"code":10000,"message":"Authentication error"}]'
```
#### Steps to Reproduce:
1. Configure the `serverless.yml` file with valid Cloudflare credentials (both global API key and user API tokens have been tested).
2. Run `serverless deploy`.
3. Observe the authentication error.
#### Expected Behavior:
The expected behavior is a successful deployment of the Cloudflare Worker without authentication errors.
#### Actual Behavior:
An authentication error is thrown, despite the credentials being valid and successfully tested with a direct API request.
#### Environment Information:
- Operating System: Linux
- Node.js Version: 18.17.1
- Serverless Framework Version: 3.34.0
- `serverless-cloudflare-workers` Plugin Version: 6.2.3
#### Serverless Configuration File:
```yaml
service: workers
frameworkVersion: '3'
provider:
name: cloudflare
config:
accountId: XXX
zoneId: XXX
functions:
hello:
name: hello
script: helloWorld
events:
- http:
url: XXX.com/*
method: GET
plugins:
- serverless-cloudflare-workers
```
#### Additional Information:
I have verified that the credentials are correct by successfully making a curl request to the Cloudflare API using the same email and API key. Both the global API key and user API tokens have been tested, and the issue persists.
#### Debugging logs from HTTP Request that fails
```js
HTTP 6515: call onSocket 1 0
HTTP 6515: createConnection api.cloudflare.com:443::::::::::::::::::::: [Object: null prototype] {
protocol: 'https:',
slashes: true,
auth: null,
host: 'api.cloudflare.com',
port: 443,
hostname: 'api.cloudflare.com',
hash: null,
search: null,
query: null,
pathname: '/client/v4/zones/719f8095c76c951d3ed6b058f0dab9ca/workers/settings',
path: null,
href: 'https://api.cloudflare.com/client/v4/zones/719f8095c76c951d3ed6b058f0dab9ca/workers/settings',
method: 'GET',
headers: [Object: null prototype] {
'X-Auth-Email': [ 'XXX' ],
'X-Auth-Key': [ 'XXX' ],
Accept: [ '*/*' ],
'User-Agent': [ 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)' ],
'Accept-Encoding': [ 'gzip,deflate' ]
},
agent: undefined,
_defaultAgent: Agent {
_events: [Object: null prototype] {
free: [Function (anonymous)],
newListener: [Function: maybeEnableKeylog]
},
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object: null prototype] { noDelay: true, path: null },
requests: [Object: null prototype] {},
sockets: [Object: null prototype] {
'api.cloudflare.com:443:::::::::::::::::::::': [Array]
},
freeSockets: [Object: null prototype] {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 1,
maxCachedSessions: 100,
_sessionCache: { map: {}, list: [] },
[Symbol(kCapture)]: false
},
noDelay: true,
servername: 'api.cloudflare.com',
_agentKey: 'api.cloudflare.com:443:::::::::::::::::::::'
}
HTTP 6515: sockets api.cloudflare.com:443::::::::::::::::::::: 2 2
HTTP 6515: outgoing message end.
(node:6515) Warning: Setting the NODE_DEBUG environment variable to 'http' can expose sensitive data (such as passwords, tokens and authentication headers) in the resulting log.
(Use `node --trace-warnings ...` to show where the warning was created)
HTTP 6515: AGENT incoming response!
HTTP 6515: AGENT socket.destroySoon()
HTTP 6515: AGENT incoming response!
HTTP 6515: AGENT socket.destroySoon()
HTTP 6515: CLIENT socket onClose
HTTP 6515: removeSocket api.cloudflare.com:443::::::::::::::::::::: writable: false
HTTP 6515: HTTP socket close
HTTP 6515: CLIENT socket onClose
HTTP 6515: removeSocket api.cloudflare.com:443::::::::::::::::::::: writable: false
HTTP 6515: HTTP socket close
[{"code":10000,"message":"Authentication error"}]
HTTP 6515: call onSocket 0 0
```
Contributor guide
Assessment
This issue has not been assessed yet.