Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Authentication for /stats and /metrics #14

Closed
sv2 opened this issue Sep 1, 2017 · 1 comment
Closed

Support Authentication for /stats and /metrics #14

sv2 opened this issue Sep 1, 2017 · 1 comment
Assignees

Comments

@sv2
Copy link
Collaborator

sv2 commented Sep 1, 2017

Provide option to enable authentication for statistics API (/swagger-stats/stats) and metrics API (/swagger-stats/metrics)

@sv2 sv2 self-assigned this Sep 1, 2017
@sv2 sv2 added the enhancement label Sep 1, 2017
@sv2 sv2 added this to v1.0.0 in swagger-stats Sep 2, 2017
sv2 added a commit that referenced this issue Nov 1, 2017
@sv2 sv2 moved this from v1.0.0 to 0.94.0 in swagger-stats Nov 1, 2017
sv2 added a commit that referenced this issue Nov 2, 2017
sv2 added a commit that referenced this issue Nov 3, 2017
sv2 added a commit that referenced this issue Nov 4, 2017
@sv2 sv2 closed this as completed in 7566c40 Nov 7, 2017
@sv2
Copy link
Collaborator Author

sv2 commented Nov 7, 2017

swagger-stats now supports Basic Authentication for /stats and /metrics endpoints.

Example how to enable Basic Authentication:

var maxAge = 900; // basic auth session expiration in seconds

// Use swagger-stats middleware with authentication enabled
app.use(swStats.getMiddleware({
    name: 'swagger-stats-authtest',
    version: '0.94.0',
    hostname: "hostname",
    ip: "127.0.0.1",
    swaggerSpec:swaggerSpec,
    uriPath: '/swagger-stats',
    durationBuckets: [10, 25, 50, 100, 200],
    requestSizeBuckets: [10, 25, 50, 100, 200],
    responseSizeBuckets: [10, 25, 50, 100, 200],
    apdexThreshold: 100,
    onResponseFinish: function(req,res,rrr){
        debug('onResponseFinish: %s', JSON.stringify(rrr));
    },
    authentication: true,
    sessionMaxAge: maxAge,
    onAuthenticate: function(req,username,password){
        // simple check for username and password
        return((username==='swagger-stats') && (password==='swagger-stats') );
    }
}));

See examples/authtest for full example

For /stats endpoint, swagger-stats supports session and will set up cookie 'sws-session-id'. Application can control session expiration using sessionMaxAge parameter ( value in seconds )

For /metrics endpoint sessions are not used as Prometheus will send username and password in every scrape rewquest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant