openfaas / nats-queue-worker

Queue-worker for OpenFaaS with NATS Streaming
https://docs.openfaas.com/reference/async/
MIT License
129 stars 59 forks source link

Posting function statistics to the gateway returns http status 401 #116

Closed welteki closed 2 years ago

welteki commented 2 years ago

The queue worker fails to post reports back to the gateway when gateway_invoke is false and basic_auth is set to "1".

Expected Behaviour

Posting reports back to the gateway should return http status 202.

Current Behaviour

When gateway_invoke is false and the basic_auth env variable is set to "1" posting a report back to the gateway fails with http status 401.

queue-worker logs:

[#1] Invoking: figlet with 6 bytes, via: http://figlet.openfaas-fn.svc.cluster.local:8080/
[#1] Invoked: figlet [200] in 0.016794s
[#1] figlet returned 138 bytes
[#1] Posting report for figlet, status: 401

Possible Solution

The postReport function gets the value of the bacic_auth env variable but only accepts the string "true" to be thruty while ReadConfig accepts "1" and "true" to be thruty. https://github.com/openfaas/nats-queue-worker/blob/b5f165b01f8501b19b651a8df88274aabf70a829/main.go#L318-L320

Two possible solutions:

  1. Pass config as an argument to the postReport function and use the value of the BasicAuth field in the above mentioned conditional.
  2. Skip the check of the basic_auth value since credentials will always be nil if config.BasicAuth is false. https://github.com/openfaas/nats-queue-worker/blob/b5f165b01f8501b19b651a8df88274aabf70a829/main.go#L39-L48

Steps to Reproduce (for bugs)

  1. Deploy openfaas on Kubernetes using arkade.
  2. Update the queue-worker deployment and change the following env variables.
    - name: gateway_invoke
    value: "false"
    - name: basic_auth
    value: "1"
  3. Deploy a function and invoke it async

Context

Your Environment

alexellis commented 2 years ago

I think the suggestion makes sense.

Please send a PR to use config.BasicAuth instead of checking the env-var.