cloudflare / serverless-cloudflare-workers

Serverless provider plugin for Cloudflare Workers
BSD 3-Clause "New" or "Revised" License
175 stars 37 forks source link

Authentication Error When Deploying Cloudflare Worker with Valid Credentials #78

Open paw-j opened 1 year ago

paw-j commented 1 year ago

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 guideline

export CLOUDFLARE_AUTH_KEY=YOUR_API_KEY_HERE
export CLOUDFLARE_AUTH_EMAIL=YOUR_CLOUDFLARE_EMAIL

Error Message:

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:

Serverless Configuration File:

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

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