Spark+Scala App如何鉴权授权到云对象存储?

How to authenticate and authorize Spark+Scala App to Cloud Object Storage?

我正在尝试 运行 Bluemix 上的 Spark+Scala 应用程序使用 spark-submit.sh. So far, based on documentation and source code 我想出了以下代码片段:

val spark: SparkSession = SparkSession
  .builder
  .appName("app")
  .config("spark.hadoop.fs.cos.softlayer.endpoint",
          "s3-api.us-geo.objectstorage.service.networklayer.com")
  .config("spark.hadoop.fs.cos.softlayer.access.key",
          "auto-generated-apikey-<redacted>")
  .config("spark.hadoop.fs.cos.softlayer.secret.key",
          "<redacted>")
  .getOrCreate()
spark.sparkContext.setLogLevel("TRACE")
spark.sparkContext.textFile("s3d://<bucket>.softlayer/<file>")

失败

Exception in thread "Driver" java.lang.NullPointerException
        at com.ibm.stocator.fs.common.ObjectStoreGlobber.glob(ObjectStoreGlobber.java:179)
        at com.ibm.stocator.fs.ObjectStoreFileSystem.globStatus(ObjectStoreFileSystem.java:443)
        at org.apache.hadoop.mapred.FileInputFormat.singleThreadedListStatus(FileInputFormat.java:259)

由于

DEBUG apache.http.headers: http-outgoing-0 << HTTP/1.1 403 Forbidden

我相信 403 意味着 "authentication was successful, but authorization was not",但即使我将我的凭据更改为随机的东西,我仍然得到 403。

我将我的服务帐户配置为 Reader 所有 'cloud-object-storage' 资源。

相同的凭据在 中对我来说很好用。

我错过了什么?

遗憾的是,AE beta 的当前文档引用了 IaaS version of COS,它使用 AWS 样式 (HMAC) 凭证进行身份验证,而不是 IBM Cloud IAM 提供的 API 密钥。今年晚些时候将在支持 IAM 的 COS 中支持 HMAC 凭据。

AE 文档应该会尽快更新,其中包含使用 API 密钥连接到 COS 的示例。同时,请尝试以下配置语法:

.config("spark.hadoop.fs.cos.iamservice.iam.endpoint",
          "https://iam.ng.bluemix.net/oidc/token")   
.config("spark.hadoop.fs.cos.iamservice.endpoint",
          "s3-api.us-geo.objectstorage.service.networklayer.com")
.config("spark.hadoop.fs.cos.iamservice.iam.api.key",
          "<api-key>")
.config("spark.hadoop.fs.cos.iamservice.iam.service.id",
          "<resource-instance-id>")