DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Databases
  4. Using NGINX for Targeted Access to the Sensu Core 1.4 API

Using NGINX for Targeted Access to the Sensu Core 1.4 API

Let's take a look at using NGINX for tageted access to the Sensu Core 1.4 APi. Also explore the backstory.

Jef Spaleta user avatar by
Jef Spaleta
·
Sep. 13, 18 · Tutorial
Like (1)
Save
Tweet
Share
4.18K Views

Join the DZone community and get the full member experience.

Join For Free

This is a first in a series of posts under the banner “Jef Practices” — short, technical how-to articles focused on sharing useful tips to help make better use of Sensu. Think of these posts as conversation starters for approaches to common challenges you’ll run into as your Sensu usage grows in complexity.

Summary

NGINX can be used as a proxy to provide authenticated access to specific endpoints for any RESTful service API, including the Sensu API. Below, I provide an NGINX configuration to grant external service providers narrow access to only create check results in the Sensu 1.4 API external service providers. But first, here's some backstory of how I got here.

Backstory

I was working on integrating my Sensu 1.x install with Particle.io a couple of weeks ago — I’ll write that up in more detail soon. I’m just getting started with Particle IoT devices, but I have an interesting personal project in mind for an IoT network that involves driving data into the Sensu event pipeline.

I find IoT networks quite fascinating: they're really making it possible to cost-effectively instrument much of our physical environment. If you want to be inspired, take a look at this article about how Particle devices are being used to monitor the deadly volcanic emissions in Hawaii.

While working on driving a check result into Sensu from my Particle device, I found I needed to expose the Sensu 1.4 results API to the particle service to make use of Particle.io’s webhook integration. Particle.io is an external service outside of my control, so I don’t want to trust it with access beyond what is absolutely necessary. Here's a rundown of security precautions I’m looking to enforce:

  • Only allow Particle.io webhook access to the Sensu 1.4 API /results POST endpoint.
  • Make sure the Particle.io webhook has its own user/password separate from other API access so I can revoke Particle.io access without retooling other integrations.
  • Use encrypted communication across the public network from Particle.io to my Sensu API service.

To accomplish all this, I set up a little NGINX reverse proxy to provide very narrow access that I could use to post check results — and that’s all. I thought it was a useful enough config to share with everyone, as this is a pattern that can be used for any external service integration. Below, you’ll find the cut-down server directive used in my nginx.conf.

A Narrow-Minded NGINX Proxy Config

server {

  listen    8080 default_server;
  listen    [::]:8080 default_server;
  server_name _;
  root      /usr/share/nginx/html;   # Enable SSL using certs obtained via certbot
  # Checkout ‘Getting Started’ guide using letsencrypt.org 
 # You'll need to adjust the cert paths accordingly.
 ssl on;
 ssl_certificate /etc/letsencrypt/live/a.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/a.com/privkey.pem;
  ssl_session_cache shared:SSL:10m;   # Match results endpoint exactly
 location = /results {    # Only allow POST to the /results endpoint 
 limit_except POST {
 deny all;
 }  
    # Setup basic http auth
 auth_basic "Restricted Access!";
    auth_basic_user_file /etc/nginx/conf.d/.htpasswd;   # setup as a proxy for the actual Sensu API service
 proxy_pass http://127.0.0.1:4567;
 proxy_set_header Host $host; # needed if using Sensu 1.x config has http auth enabled
 # string is base64 encoded “user:password”
 #proxy_set_header Authorization "Basic dXNlckBwYXNzd29yZAo=";   }
}

The referenced .htpasswd file contains whatever user/password combinations I want to require. I generate a different authentication for each external service I’d like to create check results to isolate service authentication.

This NGINX configuration example uses a Sensu 1.4 API process running on localhost with auth disabled and relies on firewall rules to hide the Sensu API from the external network, treating all localhost access as trusted. If you want to proxy a Sensu 1.x API service with auth enabled, you can uncomment the proxy_set_header authorization line and replace the base64 encoded string representing the Sensu API user and password.

With Sensu 2.0 — now in beta — none of this is necessary. The role-based access control baked into Sensu 2.0 makes it possible for me to define a specific role with its own password that has narrow access to create events — I’ll cover that in more detail in the afore-promised Particle.io integration article. In the meantime, stay tuned for more “Jef Practices” on the Sensu blog.

API

Published at DZone with permission of Jef Spaleta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Solving the Kubernetes Security Puzzle
  • Testing Level Dynamics: Achieving Confidence From Testing
  • Microservices Testing
  • Using Swagger for Creating a PingFederate Admin API Java Wrapper

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: