Access XPack user's username from a plugin


#1

We have XPack installed on ES / Kibana 5.5.1. Is it possible from within a plugin to access the current Kibana user's username, and optionally if the user is viewing a dashboard to retrieve the dashboard name (not the hash)?

I have tried various service / uiExport combinations to no avail.

// Main plugin registration.
exports.default = function (kibana) {
  return new kibana.Plugin({
                id: 'bit_test_plugin',
                require: ['kibana', 'elasticsearch'],

                // There are a couple of ways to inject content into Kibana,
                // all of them are defined here. "hacks" is special in that it 
                // loads on every pages, whereas app may only load when the user
                // visits your plugin directly.
                uiExports: {
                        chromeNavControls: [
                                'plugins/bit_test_plugin/branding'
                        ],
                        hacks: [
                                'plugins/bit_test_plugin/hack.js'
                        ],
                        app: {
                                title: 'BIT Test Plugin',
                                description: 'Performs logging and adds custom navigation',
                                main: 'plugins/bit_test_plugin/app',
                                hidden: false // In production we will hide this
                        }
                },
                init(server, options){
                        console.warn('Init BIT Test Plugin from index.js');

                        // This defines an API request when you access 
                        // http://<kibana_url>/api/bit_test_plugin/ping
                        // We will use this to send the module 1000 ping since 
                        // we can access user IP address and hopefully one day get
                        // the dashboard name.
                        server.route({
                                path: '/api/bit_test_plugin/ping',
                                method: 'GET',
                                handler(req, reply) {
                                        // more to come here in the next step
                                        reply("Hello World");

                                        // We have the IP Address!
                                        var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

                                        // TODO: Find dashbaord name! Note: This should only be available when 
                                        // Viewing a dashboard. We only want to log when users are viewing dashboards.
                                        var dashboard = "";

                                        if(dashboard != "")
                                                console.warn("User's IP Address: " + ip + " User is viewing dashboard: " + dashboard);
                                        else
                                                console.log("User is not viewing a dashboard");
                                }
                        });
                }
  });
};

module.exports = exports['default'];

(CJ Cenizal) #2

Hi there, we don't yet officially support plugin development, so I won't be able to fully answer your question. However, there's some info available at How to get currently logged in USERID in plugin? which looks relevant and might be able to help you.

Thanks,
CJ


(system) #3

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