Alloy: authentication error: invalid token

Hello, I’m using Grafana Cloud and on my node that I want to monitor logs from, when running ./alloy-linux-amd64 run config.alloy I am getting error:

level=error msg="final error sending batch"
component_path=/remotecfg/self_monitoring_logs_linux.default
component_id=loki.write.grafana_cloud_loki component=client
host=logs-prod-024.grafana.net status=401 tenant=""
error="server returned HTTP status 401 Unauthorized (401):
{\"status\":\"error\",\"error\":\"authentication error: invalid token\"}"

What surprises me is that all configurations have been made using the Grafana Cloud provided script for both Alloy and Collector.

I cannot test the credentials because Grafana Cloud disables access to them:

My config.alloy as follows:

cat config.alloy 
remotecfg {
	url            = "https://fleet-management-prod-0XX.grafana.net"
	id             = "atl"
	poll_frequency = "60s"

	basic_auth {
		username = "1308XXX"
		password = "glc_eyJvIjoiMTQ3NTcxMyIsIm4iXXXXXXXXXXXXXXXXwibSI6eyJyIjoicHJvZC1zYS1lYXN0LTEifX0="
	}
}

prometheus.remote_write "metrics_service" {
	endpoint {
		url = "https://prometheus-prod-XXX-1.grafana.net/api/prom/push"

		basic_auth {
			username = "254XXXX"
			password = "glc_eyJvIjoiMTQ3NTcxMyIsIm4iXXXXXXXXXXXXXXXXwibSI6eyJyIjoicHJvZC1zYS1lYXN0LTEifX0="
		}
	}
}

loki.write "grafana_cloud_loki" {
	endpoint {
		url = "https://logs-prod-Xx.grafana.net/loki/api/v1/push"

		basic_auth {
			username = "126xxxxx"
			password = "glc_eyJvIjoiMTQ3NTcxMyIsIm4iXXXXXXXXXXXXXXXXwibSI6eyJyIjoicHJvZC1zYS1lYXN0LTEifX0="
		}
	}
}
local.file_match "local_files" {
     path_targets = [{"__path__" = "/opt/atlassian/jira/logs*.*"}]
     sync_period = "5s"
 }

You can try this solution to resolve your issue. I hope it will be helpful for you
Step :1 Verify You’re Using the Correct Username & Token for Loki

Grafana Cloud > Connections > Data Sources > Loki > Authentication section


loki.write "grafana_cloud_loki" {
  endpoint {
    url = "https://logs-prod-xx.grafana.net/loki/api/v1/push"
    basic_auth {
      username = "126xxxxx"  # <- Must match Grafana Loki datasource username
      password = "glc_..."    # <- Must be the Loki API key token
    }
  }
}

Step : 2 Confirm the Token Hasn’t Expired or Been Revoked
Grafana Cloud > Access Policies and confirm that the token you’re using (glc_...) is still active and has permissions for Loki (logs).

regenerate a new API token from Grafana Cloud > Security > API Keys selecting the correct Loki push access.
Step : 3 check Api Endpoints
Make sure the URL used is correct. From your config:

url = "https://logs-prod-Xx.grafana.net/loki/api/v1/push"

Step : 4 Verify the Credentials

curl -u ‘126xxxxx:glc_XXXXX’ -X
POST https://logs-prod-xx.grafana.net/loki/api/v1/push -d