Getting 403 forbidden error while starting service for uptime monitoring

Hi,

I am trying to setup Uptime Monitoring for our application URL, and trying to setup the Elastic Observability Uptime Monitoring.

While executing the below getting 403 Forbidden Error:
.\heartbeat.exe setup

Error:
PS C:\Program Files\HeartBeat> .\heartbeat.exe setup
Exiting: couldn't connect to any of the configured Elasticsearch hosts. Errors: [error connecting to Elasticsearch at https://xxxx.azure.elastic-cloud.com:9243/: 403 Forbidden: Elastic

NOTE: I have the admin access to Elastic Instance URL https://xxxx.azure.elastic-cloud.com:9243/ and connect using my Azure AD login.

Below is the heartbeat.yml:

################### Heartbeat Configuration Example #########################

# This file is an example configuration file highlighting only some common options.
# The heartbeat.reference.yml file in the same directory contains all the supported options
# with detailed comments. You can use it for reference.
#
# You can find the full configuration reference here:
# https://www.elastic.co/guide/en/beats/heartbeat/index.html

############################# Heartbeat ######################################

# Define a directory to load monitor definitions from. Definitions take the form
# of individual yaml files.
heartbeat.config.monitors:
  # Directory + glob pattern to search for configuration files
  path: ${path.config}/monitors.d/*.yml
  # If enabled, heartbeat will periodically check the config.monitors path for changes
  reload.enabled: true
  # How often to check for changes
  reload.period: 5s

# Configure monitors inline
heartbeat.monitors:
- type: https
  enabled: true
  schedule: "@every 10s"
 # urls: ["http://elastic.co/"]
  urls: ["https://xxxx.cloudapp.azure.com/xx-frontend/"]
  check.response.code: 200
  cloud.id: ""
  cloud.auth: "elastic:${ES_USER}"

# Experimental: Set this to true to run heartbeat monitors exactly once at startup
#heartbeat.run_once: true

# ======================= Elasticsearch template setting =======================

setup.template.settings:
  index.number_of_shards: 1
  index.codec: best_compression
  #_source.enabled: false

# ================================== General ===================================

# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.
#name:

# The tags of the shipper are included in their own field with each
# transaction published.
tags: ["elk"]

# Optional fields that you can specify to add additional information to the
# output.
#fields:
#  env: staging


# =================================== Kibana ===================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:

  # Kibana Host
  # Scheme and port can be left out and will be set to the default (http and 5601)
  # In case you specify and additional path, the scheme is required: http://localhost:5601/path
  # IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
  host: "https://xxx.elastic-cloud.com:9243/"

  # Kibana Space ID
  # ID of the Kibana Space into which the dashboards should be loaded. By default,
  # the Default Space will be used.
  #space.id:

# =============================== Elastic Cloud ================================

# These settings simplify using Heartbeat with the Elastic Cloud (https://cloud.elastic.co/).

# The cloud.id setting overwrites the `output.elasticsearch.hosts` and
# `setup.kibana.host` options.
# You can find the `cloud.id` in the Elastic Cloud web UI.
#cloud.id:

# The cloud.auth setting overwrites the `output.elasticsearch.username` and
# `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
#cloud.auth:

# ================================== Outputs ===================================

# Configure what output to use when sending the data collected by the beat.

# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["https://xxx.azure.elastic-cloud.com:9243/"]

  # Protocol - either `http` (default) or `https`.
  protocol: "https"

  # Authentication credentials - either API key or username/password.
  api_key: ""
  #username: "${ES_USER}"
  #password: "${ES_PASS}"

# ------------------------------ Logstash Output -------------------------------
#output.logstash:
  # The Logstash hosts
  #hosts: ["localhost:5044"]

  # Optional SSL. By default is off.
  # List of root certificates for HTTPS server verifications
  #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]

  # Certificate for SSL client authentication
  #ssl.certificate: "/etc/pki/client/cert.pem"

  # Client Certificate Key
  #ssl.key: "/etc/pki/client/cert.key"

# ================================= Processors =================================

processors:
  - add_observer_metadata:
      # Optional, but recommended geo settings for the location Heartbeat is running in
      #geo:
        # Token describing this location
        #name: us-east-1a
        # Lat, Lon "
        #location: "37.926868, -78.024902"


# ================================== Logging ===================================

# Sets log level. The default log level is info.
# Available log levels are: error, warning, info, debug
logging.level: debug

# At debug level, you can selectively enable logging only for some components.
# To enable all selectors use ["*"]. Examples of other selectors are "beat",
# "publisher", "service".
logging.selectors: ["*"]

#logging.to_files: true
#logging.files:
#path: /var/log/heartbeat
#name: heartbeat
#keepfiles: 7
#permissions: 0644

# ============================= X-Pack Monitoring ==============================
# Heartbeat can export internal metrics to a central Elasticsearch monitoring
# cluster.  This requires xpack monitoring to be enabled in Elasticsearch.  The
# reporting is disabled by default.

# Set to true to enable the monitoring reporter.
#monitoring.enabled: false

# Sets the UUID of the Elasticsearch cluster under which monitoring data for this
# Heartbeat instance will appear in the Stack Monitoring UI. If output.elasticsearch
# is enabled, the UUID is derived from the Elasticsearch cluster referenced by output.elasticsearch.
#monitoring.cluster_uuid:

# Uncomment to send the metrics to Elasticsearch. Most settings from the
# Elasticsearch output are accepted here as well.
# Note that the settings should point to your Elasticsearch *monitoring* cluster.
# Any setting that is not set is automatically inherited from the Elasticsearch
# output configuration, so if you have the Elasticsearch output configured such
# that it is pointing to your Elasticsearch monitoring cluster, you can simply
# uncomment the following line.
#monitoring.elasticsearch:
 # api_key: ""

# ============================== Instrumentation ===============================

# Instrumentation support for the heartbeat.
#instrumentation:
    # Set to true to enable instrumentation of heartbeat.
    #enabled: false

    # Environment in which heartbeat is running on (eg: staging, production, etc.)
    #environment: ""

    # APM Server hosts to report instrumentation results to.
    #hosts:
    #  - http://localhost:8200

    # API Key for the APM Server(s).
    # If api_key is set then secret_token will be ignored.
    #api_key:

    # Secret token for the APM Server(s).
    #secret_token:


# ================================= Migration ==================================

# This allows to enable 6.7 migration aliases
#migration.6_to_7.enabled: true

Also when I test the output:
PS C:\Program Files\HeartBeat> .\heartbeat.exe -c .\heartbeat.yml test output
elasticsearch: https://xxxx.azure.elastic-cloud.com:9243/...
parse url... OK
connection...
parse host... OK
dns lookup... OK
addresses: 11.xx.xx.xx
dial up... OK
TLS...
security: server's certificate chain verification is enabled
handshake... OK
TLS version: TLSv1.2
dial up... OK
talk to server... ERROR 403 Forbidden: Elastic

Could you please assist me on this?

Thanks
Seshadri

Hi @amseshadri, thanks for getting in touch.

Can you double check the role and the user through which you're trying to connect in your Heartbeat config? It may be the case that it is able to authenticate just fine, but that Heartbeat doesn't have the necessary permissions to do the actions it must.

I'd recommend double checking this page Grant privileges and roles needed for setup | Heartbeat Reference [8.3] | Elastic and having another look at your config. That may help.

Otherwise, let me know what you found out with regards to roles and we can attempt other approaches.

Hi @lucasfcosta
Thanks Much for your response, I already created a role 'heartbeat_writer' as below:

Mapped this role as part of the Role Mapping as below:

But somehow i'm still facing the issue. :frowning:

I am having admin access use to login with my Azure AD to our Elastic Dev Instance.

Please suggest.

Thanks
Seshadri

Hi @amseshadri, did you try adding the "write" privilege to that index?

That would ensure that whoever has this role can write to this index.

There are more docs about each particular index privilege here: Security privileges | Elasticsearch Guide [8.3] | Elastic.

This topic was automatically closed 24 days after the last reply. New replies are no longer allowed.