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

[WIP] Inspector server authentication #12

Closed

Conversation

enoodle
Copy link
Contributor

@enoodle enoodle commented Apr 17, 2016

Currently I implemented only one type of authentication with token through kubernetes. If we want this can be changed to a more configurable and with other sophisticated authentication methods. I added a new argument to the image inspector --server-auth-type and the current possible values are None (default) and KubernetesToken

based on #11 for convenience.

@simon3z
Copy link
Owner

simon3z commented Apr 18, 2016

@enoodle the token must not be passed as a parameter.

Secrets should be passed either as env variables or files.

The single-token authentication implementation as in this PR is nice but I would set it aside for now, because the most interesting one is to demand to kubernetes the authentication/authorization.

E.g. similar to what hawkular-metrics does (but with different rules), here.

    private boolean isAuthorized(String method, String token, String projectId) {
        try {
            String verb = getVerb(method);

            String path = "/oapi/v1/subjectaccessreviews";
            URL url = new URL(KUBERNETES_MASTER_URL + path);

            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

            //Configure the outgoing request
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);
            //Set Headers
            connection.setRequestProperty("Accept", "application/json");
            connection.setRequestProperty("Content-type", "application/json");
            connection.setRequestProperty("Authorization", token);

            //Add the body
            try (
                OutputStream outputStream = connection.getOutputStream();
            ) {
                for (byte b : generateSubjectAccessReview(projectId, verb).getBytes()) {
                    outputStream.write(b);
                }
            }

            //Perform the Operation
            connection.connect();
            int responseCode = connection.getResponseCode();
            if (responseCode == 201) {
                ObjectMapper objectMapper = new ObjectMapper();
                JsonNode jsonNode = objectMapper.readTree(connection.getInputStream());

                if (jsonNode.get("allowed").asText().equals("true")) {
                    return true;
                }

            } else {
                return false;
            }

        } catch (IOException e) {
            logger.error("Error trying to authenticate against the OpenShift server", e);
        }

        return false;
    }

And remember that here we have the advantage of being a Go application, which means that you can use the "official" kubernetes client library (no need for low-level http rest-api requests).

cc @pweil-

Note: We'll have to check how to pass headers through the kubernetes api-server proxy.

@enoodle enoodle force-pushed the inspector_server_authentication branch from fd16ee8 to 708715e Compare April 24, 2016 15:59
@enoodle enoodle changed the title Inspector server authentication [WIP] Inspector server authentication Apr 24, 2016
@enoodle enoodle force-pushed the inspector_server_authentication branch from 708715e to 502f26f Compare April 24, 2016 16:05
@enoodle
Copy link
Contributor Author

enoodle commented Apr 24, 2016

@simon3z I am not 100% sure that this is the correct use of that API. It is more the check if a user is authorized to access a certain resource in the system than to authenticate the user. here hawkular is changing the token to also authenticate but i am not sure that this whole thing is working as you intend. Might be that I am wrong.

@enoodle enoodle force-pushed the inspector_server_authentication branch 2 times, most recently from bde7f6f to dbf1860 Compare April 27, 2016 14:17
@enoodle enoodle force-pushed the inspector_server_authentication branch from dbf1860 to 79f12dc Compare April 28, 2016 08:38
simon3z added a commit that referenced this pull request May 16, 2016
Backported patches for 2.0.1
@simon3z
Copy link
Owner

simon3z commented Feb 21, 2017

Please move this to https://github.com/openshift/image-inspector/

@simon3z simon3z closed this Feb 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants