spring-cloud-dataflow icon indicating copy to clipboard operation
spring-cloud-dataflow copied to clipboard

scdf shell : 401 Unauthorized'. Unauthorized, did you forget to authenticate?

Open eskuai opened this issue 6 years ago • 8 comments

Description: As I user, i wanto to use shell jar to deploy streams.
I am running with security with keycloak, and, following documentation, i think that a valid command could be: java -jar spring-cloud-dataflow-shell-2.3.0.RELEASE.jar --dataflow.uri=http://scdf2-server-data-flow-server:8080 --dataflow.username=dataflow --dataflow.password=<valid-pasword> --dataflow.credentials-provider-command=echo "Bearer <valid token" --dataflow.skip-ssl-validation=true --debug Reading doks, refers to "username", and, I am not sure if is keycloak user or client. Tested both of them


2.3.0.RELEASE

Welcome to the Spring Cloud Data Flow shell. For assistance hit TAB or type "help".
2020-01-21T14:23:42+0100 DEBUG Spring Shell o.s.w.HttpLogging:147 - HTTP GET http://scdf2-server-data-flow-server:8080/login/security/info
2020-01-21T14:23:42+0100 DEBUG Spring Shell o.s.w.HttpLogging:147 - Accept=[application/json, application/*+json]
2020-01-21T14:23:42+0100 DEBUG Spring Shell o.s.w.HttpLogging:147 - Response 401 UNAUTHORIZED
2020-01-21T14:23:42+0100 DEBUG Spring Shell o.s.w.c.HttpMessageConverterExtractor:102 - Reading to [org.springframework.hateoas.mediatype.vnderrors.VndErrors]
WARNING - Problem connecting to the Spring Cloud Data Flow Server:
"Unable to access Data Flow Server at 'http://scdf2-server-data-flow-server:8080/login': 'org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 Unauthorized'. Unauthorized, did you forget to authenticate?"
Please double check your startup parameters and either restart the Data Flow Shell (with any missing configuration including security etc.) or target the Data Flow Server using the 'dataflow config server' command.
server-unknown:>[root@kcurl http://scdf2-server-data-flow-server:8080/security/info

But, the available rest functions are:

{
"_links": {
"dashboard": {
"href": "http://scdf2-server-data-flow-server:8080/dashboard"
},
"audit-records": {
"href": "http://scdf2-server-data-flow-server:8080/audit-records"
},
"streams/definitions": {
"href": "http://scdf2-server-data-flow-server:8080/streams/definitions"
},
"streams/definitions/definition": {
"href": "http://scdf2-server-data-flow-server:8080/streams/definitions/{name}",
"templated": true
},
"streams/validation": {
"href": "http://scdf2-server-data-flow-server:8080/streams/validation/{name}",
"templated": true
},
"runtime/streams": {
"href": "http://scdf2-server-data-flow-server:8080/runtime/streams?names={names}",
"templated": true
},
"runtime/apps": {
"href": "http://scdf2-server-data-flow-server:8080/runtime/apps"
},
"runtime/apps/{appId}": {
"href": "http://scdf2-server-data-flow-server:8080/runtime/apps/{appId}",
"templated": true
},
"runtime/apps/{appId}/instances": {
"href": "http://scdf2-server-data-flow-server:8080/runtime/apps/{appId}/instances",
"templated": true
},
"runtime/apps/{appId}/instances/{instanceId}": {
"href": "http://scdf2-server-data-flow-server:8080/runtime/apps/{appId}/instances/{instanceId}",
"templated": true
},
"streams/deployments": {
"href": "http://scdf2-server-data-flow-server:8080/streams/deployments"
},
"streams/deployments/{name}": {
"href": "http://scdf2-server-data-flow-server:8080/streams/deployments/{name}",
"templated": true
},
"streams/deployments/history/{name}": {
"href": "http://scdf2-server-data-flow-server:8080/streams/deployments/history/{name}",
"templated": true
},
"streams/deployments/manifest/{name}/{version}": {
"href": "http://scdf2-server-data-flow-server:8080/streams/deployments/manifest/{name}/{version}",
"templated": true
},
"streams/deployments/platform/list": {
"href": "http://scdf2-server-data-flow-server:8080/streams/deployments/platform/list"
},
"streams/deployments/rollback/{name}/{version}": {
"href": "http://scdf2-server-data-flow-server:8080/streams/deployments/rollback/{name}/{version}",
"templated": true
},
"streams/deployments/update/{name}": {
"href": "http://scdf2-server-data-flow-server:8080/streams/deployments/update/{name}",
"templated": true
},
"streams/deployments/deployment": {
"href": "http://scdf2-server-data-flow-server:8080/streams/deployments/{name}",
"templated": true
},
"streams/deployments/scale/{streamName}/{appName}/instances/{count}": {
"href": "http://scdf2-server-data-flow-server:8080/streams/deployments/scale/{streamName}/{appName}/instances/{count}",
"templated": true
},
"streams/logs": {
"href": "http://scdf2-server-data-flow-server:8080/streams/logs"
},
"streams/logs/{streamName}": {
"href": "http://scdf2-server-data-flow-server:8080/streams/logs/{streamName}",
"templated": true
},
"streams/logs/{streamName}/{appName}": {
"href": "http://scdf2-server-data-flow-server:8080/streams/logs/{streamName}/{appName}",
"templated": true
},
"tasks/platforms": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/platforms"
},
"tasks/definitions": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/definitions"
},
"tasks/definitions/definition": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/definitions/{name}",
"templated": true
},
"tasks/executions": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/executions"
},
"tasks/executions/name": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/executions{?name}",
"templated": true
},
"tasks/executions/current": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/executions/current"
},
"tasks/executions/execution": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/executions/{id}",
"templated": true
},
"tasks/validation": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/validation/{name}",
"templated": true
},
"tasks/logs": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/logs/{taskExternalExecutionId}{?platformName}",
"templated": true
},
"tasks/schedules": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/schedules"
},
"tasks/schedules/instances": {
"href": "http://scdf2-server-data-flow-server:8080/tasks/schedules/instances/{taskDefinitionName}",
"templated": true
},
"jobs/executions": {
"href": "http://scdf2-server-data-flow-server:8080/jobs/executions"
},
"jobs/executions/name": {
"href": "http://scdf2-server-data-flow-server:8080/jobs/executions{?name}",
"templated": true
},
"jobs/executions/execution": {
"href": "http://scdf2-server-data-flow-server:8080/jobs/executions/{id}",
"templated": true
},
"jobs/executions/execution/steps": {
"href": "http://scdf2-server-data-flow-server:8080/jobs/executions/{jobExecutionId}/steps",
"templated": true
},
"jobs/executions/execution/steps/step": {
"href": "http://scdf2-server-data-flow-server:8080/jobs/executions/{jobExecutionId}/steps/{stepId}",
"templated": true
},
"jobs/executions/execution/steps/step/progress": {
"href": "http://scdf2-server-data-flow-server:8080/jobs/executions/{jobExecutionId}/steps/{stepId}/progress",
"templated": true
},
"jobs/instances/name": {
"href": "http://scdf2-server-data-flow-server:8080/jobs/instances{?name}",
"templated": true
},
"jobs/instances/instance": {
"href": "http://scdf2-server-data-flow-server:8080/jobs/instances/{id}",
"templated": true
},
"tools/parseTaskTextToGraph": {
"href": "http://scdf2-server-data-flow-server:8080/tools"
},
"tools/convertTaskGraphToText": {
"href": "http://scdf2-server-data-flow-server:8080/tools"
},
"jobs/thinexecutions": {
"href": "http://scdf2-server-data-flow-server:8080/jobs/thinexecutions"
},
"jobs/thinexecutions/name": {
"href": "http://scdf2-server-data-flow-server:8080/jobs/thinexecutions{?name}",
"templated": true
},
"apps": {
"href": "http://scdf2-server-data-flow-server:8080/apps"
},
"about": {
"href": "http://scdf2-server-data-flow-server:8080/about"
},
"completions/stream": {
"href": "http://scdf2-server-data-flow-server:8080/completions/stream{?start,detailLevel}",
"templated": true
},
"completions/task": {
"href": "http://scdf2-server-data-flow-server:8080/completions/task{?start,detailLevel}",
"templated": true
}
},
"api.revision": 14
}

Release versions:

{
  "versionInfo": {
    "implementation": {
      "name": "spring-cloud-dataflow-server",
      "version": "2.3.0.RELEASE"
    },
    "core": {
      "name": "Spring Cloud Data Flow Core",
      "version": "2.3.0.RELEASE"
    },
    "dashboard": {
      "name": "Spring Cloud Dataflow UI",
      "version": "2.3.0.RELEASE"
    },
    "shell": {
      "name": "Spring Cloud Data Flow Shell",
      "version": "2.3.0.RELEASE",
      "url": "https://repo.spring.io/libs-release/org/springframework/cloud/spring-cloud-dataflow-shell/2.3.0.RELEASE/spring-cloud-dataflow-shell-2.3.0.RELEASE.jar"
    }
  },
  "featureInfo": {
    "streamsEnabled": true,
    "tasksEnabled": true,
    "schedulesEnabled": true,
    "grafanaEnabled": false
  },
  "securityInfo": {
    "isAuthenticationEnabled": true,
    "isAuthenticated": true,
    "username": "mk",
    "roles": [
      "ROLE_CREATE",
      "ROLE_DEPLOY",
      "ROLE_DESTROY",
      "ROLE_MANAGE",
      "ROLE_MODIFY",
      "ROLE_SCHEDULE",
      "ROLE_VIEW"
    ]
  },
  "runtimeEnvironment": {
    "appDeployer": {
      "platformSpecificInfo": {},
      "deployerImplementationVersion": "2.2.1.RELEASE",
      "deployerName": "Spring Cloud Skipper Server",
      "deployerSpiVersion": "2.2.1.RELEASE",
      "javaVersion": "1.8.0_192",
      "platformApiVersion": "",
      "platformClientVersion": "",
      "platformHostVersion": "",
      "platformType": "Skipper Managed",
      "springBootVersion": "2.2.1.RELEASE",
      "springVersion": "5.2.1.RELEASE"
    },
    "taskLaunchers": [
      {
        "platformSpecificInfo": {},
        "deployerImplementationVersion": "2.1.1.RELEASE",
        "deployerName": "KubernetesTaskLauncher",
        "deployerSpiVersion": "2.1.0.RELEASE",
        "javaVersion": "1.8.0_192",
        "platformApiVersion": "v1",
        "platformClientVersion": "unknown",
        "platformHostVersion": "unknown",
        "platformType": "Kubernetes",
        "springBootVersion": "2.2.1.RELEASE",
        "springVersion": "5.2.1.RELEASE"
      }
    ]
  },
  "grafanaInfo": {
    "url": "",
    "token": "",
    "refreshInterval": 15
  }
}

Additional context: what is /security/info?

eskuai avatar Jan 21 '20 13:01 eskuai

There's no pure basic-auth support in SCDF since v2.0. There's, however, an option to add the "Password Grant" type in OAuth, which can be set up in the desired identity provider backend (see docs). With this configured, you can then use the user/pass combination in Shell or when accessing the protected RESTful APIs outside of SCDF.

The UAA sample demonstrates this possibility both in Shell and API access.

We aren't familiar with Keycloak on how to configure this grant type, though. You may have to review their docs on this matter.

sabbyanandan avatar Jan 21 '20 14:01 sabbyanandan

Hi @sabbyanandan

Right, but I think that it is not related with keycloak. I cannot get where is the url to shell github project to open an issue in the right places

Launching:

!/bin/bash

KCHOST=http://localhost:8844
REALM=scdf23
CLIENT_ID=dataflow
CLIENT_SECRET=blablabla
UNAME=mk
PASSWORD=blablabla

ACCESS_TOKEN=`curl -s\
  -d "client_id=$CLIENT_ID" -d "client_secret=$CLIENT_SECRET" \
  -d "username=$UNAME" -d "password=$PASSWORD" \
  -d "grant_type=password" \
  "$KCHOST/auth/realms/$REALM/protocol/openid-connect/token"  | jq -r '.access_token' `

echo $ACCESS_TOKEN

and shell jar:

java  -jar spring-cloud-dataflow-shell-2.3.0.RELEASE.jar --dataflow.uri=http://scdf2-server-data-flow-server:8080  --dataflow.username=dataflow --dataflow.password=2577e86a-cb98-46db-b0ff-d509dfa7e99f --dataflow.credentials-provider-command=./token.sh --dataflow.skip-ssl-validation=true   --debug

scdf shows:

2020-01-23 11:21:50.828 DEBUG 1 --- [nio-8080-exec-2] .o.s.r.w.BearerTokenAuthenticationFilter : Authentication request for failed!
org.springframework.security.oauth2.core.OAuth2AuthenticationException: Provided token [eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJab1JGc0ZLVlQ4WHQ0ZlJSYzZUczRBT0N1LU9hVHdjdjFpMWpmQkZiQk1BIn0.eyJqdGkiOiJiOWM5YWExYy0yNDc3LTRmMzYtYWU0Ni1mYmIwYTRiYWNlOWIiLCJleHAiOjE1Nzk3NzI3NzYsIm5iZiI6MCwiaWF0IjoxNTc5NzcyNDc2LCJpc3MiOiJodHRwOi8va2V5Y2xvYWstaHR0cDo4ODQ0L2F1dGgvcmVhbG1zL3NjZGYyMyIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiI1MWFkMzIzNC1mZDU1LTQ3MGEtOTkwOS05ZGU3NzlhNzI4OWEiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJkYXRhZmxvdyIsImF1dGhfdGltZSI6MCwic2Vzc2lvbl9zdGF0ZSI6IjIyYzZkODNiLTM2NzctNGYwYi04NzI1LTdmNDllMDA5ZTg4OSIsImFjciI6IjEiLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImRhdGFmbG93Ijp7InJvbGVzIjpbInVtYV9wcm90ZWN0aW9uIiwic2NkZi1yb2xlIl19LCJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6Im9wZW5pZCBkYXRhZmxvdy5tYW5hZ2UgZGF0YWZsb3cuY3JlYXRlIGRhdGFmbG93LnZpZXcgZGF0YWZsb3cuZGVwbG95IGRhdGFmbG93LnNjaGVkdWxlIHByb2ZpbGUgZGF0YWZsb3cubW9kaWZ5IGRhdGFmbG93LmRlc3Ryb3kgZW1haWwiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImNsaWVudEhvc3QiOiIxMC40NS4wLjUiLCJjbGllbnRJZCI6ImRhdGFmbG93IiwidXNlcl9uYW1lIjoic2VydmljZS1hY2NvdW50LWRhdGFmbG93IiwicHJlZmVycmVkX3VzZXJuYW1lIjoic2VydmljZS1hY2NvdW50LWRhdGFmbG93IiwiY2xpZW50QWRkcmVzcyI6IjEwLjQ1LjAuNSJ9.Jv_o6hvwq2tTckfrzgdSTgXJSFmoJW3m4whBR1afCjIEIUjY8Tmaay-u0zZ8VSNqo-VpzdqQ5pqrN337uhRIOOkJSpgKV7hbE8I4c83Ug_Kt6BLwhuXipPk03CNvtaaO3DPtIH88bwEHEaSJIFg7_mQ3dtmeIid_qUzq8ontnEMh3IPyjaaLGrB5mHUV0JcA8oVvgfjuFrC1fTajAK3vDLhsnirBI3NKBX0gRxmMxT343Z8OKZVcO9k96O0zHHXkKZ7CzBwO_AeVFl_17YsAG9JK0zjJ0qEWDgcEKXfwJyxKc3H2yaDutFB2pGfpP4RceqMRG3F4N3ukUus6HEoTkQ] isn't active
        at org.springframework.security.oauth2.server.resource.authentication.OpaqueTokenAuthenticationProvider.authenticate(OpaqueTokenAuthenticationProvider.java:99)
        at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:175)
        at org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter.doFilterInternal(BearerTokenAuthenticationFilter.java:124)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
        at org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter.doFilterInternal(DefaultLogoutPageGeneratingFilter.java:52)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)

But the token have to be valid, because, i am using keycloak and scdf secure into the dashboard without problem before get 401...

Ok, closed Tx

eskuai avatar Jan 23 '20 10:01 eskuai

another example, why graphs works ok but history doesn.t image

vs

image

eskuai avatar Jan 23 '20 10:01 eskuai

Why does scdf needs a lot of sessions to display a page? I am the only one connected, and keycloak session shows:

image image

eskuai avatar Jan 23 '20 11:01 eskuai

Hi @sabbyanandan FYI only, Request launched to Spring security to get more info, and opened an issue into keycloak redhat support. At now, no news. It seems that you are right and the problem is about configuration (and i don't know keycloak too). Testing issue about instropect process with bash script shows that it could be possible create a different client id to apply in shell deploy. And another way, ask for help in Spring Shell It is a hard way Tx

eskuai avatar Jan 31 '20 23:01 eskuai

Hi @sabbyanandan ,

Testing again about shell deployement using scdf 2.4.0 and keycloak 8.0.1 running

Scdf 2.4.0 is secured with keycloak ...

On k8s, tunnels,

kubectl port-forward --v=1 --request-timeout=0 svc/scdf2-server-data-flow-server 8080:8080
kubectl port-forward --v=1 --request-timeout=0 svc/keycloak-http 8844:8844


master node,
k8s-master 2.3]#  java -jar spring-cloud-dataflow-shell-2.4.0.RELEASE.jar --dataflow.uri=http://localhost:8080  --dataflow.username=mk   --dataflow.password=xxxx   --skip-ssl-validation  true
  ____                              ____ _                __
 / ___| _ __  _ __(_)_ __   __ _   / ___| | ___  _   _  __| |
 \___ \| '_ \| '__| | '_ \ / _` | | |   | |/ _ \| | | |/ _` |
  ___) | |_) | |  | | | | | (_| | | |___| | (_) | |_| | (_| |
 |____/| .__/|_|  |_|_| |_|\__, |  \____|_|\___/ \__,_|\__,_|
  ____ |_|    _          __|___/                 __________
 |  _ \  __ _| |_ __ _  |  ___| | _____      __  \ \ \ \ \ \
 | | | |/ _` | __/ _` | | |_  | |/ _ \ \ /\ / /   \ \ \ \ \ \
 | |_| | (_| | || (_| | |  _| | | (_) \ V  V /    / / / / / /
 |____/ \__,_|\__\__,_| |_|   |_|\___/ \_/\_/    /_/_/_/_/_/

2.4.0.RELEASE

Welcome to the Spring Cloud Data Flow shell. For assistance hit TAB or type "help".
Successfully targeted http://localhost:8080
dataflow:>stream create --definition "time | log" --name ticktock2
Created new stream 'ticktock2'
dataflow:>stream deploy --name ticktock2
Deployment request has been sent for stream 'ticktock2'
dataflow:>stream list
╔═══════════╤═══════════╤═════════════════╤═════════════════════════════════════════╗
║Stream Name│Description│Stream Definition│                 Status                  ║
╠═══════════╪═══════════╪═════════════════╪═════════════════════════════════════════╣
║tff        │           │time | log       │The stream has been successfully deployed║
║ticktock   │           │time | log       │The stream has been successfully deployed║
║ticktock2  │           │time | log       │The stream is being deployed.            ║
╚═══════════╧═══════════╧═════════════════╧═════════════════════════════════════════╝

dataflow:>stream list
╔═══════════╤═══════════╤═════════════════╤═════════════════════════════════════════╗
║Stream Name│Description│Stream Definition│                 Status                  ║
╠═══════════╪═══════════╪═════════════════╪═════════════════════════════════════════╣
║tff        │           │time | log       │The stream has been successfully deployed║
║ticktock   │           │time | log       │The stream has been successfully deployed║
║ticktock2  │           │time | log       │The stream has been successfully deployed║
╚═══════════╧═══════════╧═════════════════╧═════════════════════════════════════════╝

dataflow:>stream lis
╔═══════════╤═══════════╤═════════════════╤═════════════════════════════════════════╗
║Stream Name│Description│Stream Definition│                 Status                  ║
╠═══════════╪═══════════╪═════════════════╪═════════════════════════════════════════╣
║tff        │           │time | log       │The stream has been successfully deployed║
║ticktock   │           │time | log       │The stream has been successfully deployed║
║ticktock2  │           │time | log       │The stream has been successfully deployed║
╚═══════════╧═══════════╧═════════════════╧═════════════════════════════════════════╝

dataflow:>stream info
You should specify a default option, otherwise known as 'name' for this command
dataflow:>stream info ticktock
╔═════════╤══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╤═══════════╤════════╗
║ Stream  │                                                            Stream Definition                                                             │Description│ Status ║
║  Name   │                                                                                                                                          │           │        ║
╠═════════╪══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╪═══════════╪════════╣
║ticktock │time --management.endpoints.web.exposure.include=prometheus,info,health --spring.cloud.streamapp.security.enabled=false | log             │           │deployed║
║         │--management.endpoints.web.exposure.include=prometheus,info,health --spring.cloud.streamapp.security.enabled=false                        │           │        ║
╚═════════╧══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╧═══════════╧════════╝

Stream Deployment properties: {
  "log" : {
    "resource" : "docker:springcloudstream/log-sink-kafka",
    "spring.cloud.deployer.group" : "ticktock",
    "version" : "2.1.2.RELEASE"
  },
  "time" : {
    "resource" : "docker:springcloudstream/time-source-kafka",
    "spring.cloud.deployer.group" : "ticktock",
    "version" : "2.1.1.RELEASE"
  }
}
dataflow:>

imagen

why don't i need a Token bearer?

Tx

eskuai avatar Feb 12 '20 12:02 eskuai

Glad you got everything working!

It appears you're using the "password-grant" type to be able to authenticate via user/pass from the Shell successfully. If you don't need the access-token based access, you don't have to pass the token bearer info when starting the Shell. The password-grant and Token access are mutually exclusive, as they are two different ways to gain access to secured SCDF's APIs.

sabbyanandan avatar Feb 12 '20 14:02 sabbyanandan

@eskuai How did you solve your issue ? I have the issue that i can login with username and password but that login with bearer token results in a 401 unauthorized

moritz31 avatar Jul 22 '20 07:07 moritz31