Skip to content

Commit 3def5dd

Browse files
authored
hdfs support keberos auth (#107)
* hdfs support krb5 * update libhdfs3 to support krb5 * hdfs support keberos auth * update ppc_builder * fix centos ci * add more logs * fix hdfs auth bug * support specify the krb5.conf * fix centos ci
1 parent 0c714dd commit 3def5dd

33 files changed

+689
-74
lines changed

.github/workflows/cpp_full_node_workflow.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ concurrency:
2222
env:
2323
RUST_BACKTRACE: 1
2424
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
25+
ACTIONS_RUNNER_FORCED_INTERNAL_NODE_VERSION: node16
26+
ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION: node16
2527

2628
jobs:
2729
build:
@@ -99,23 +101,37 @@ jobs:
99101
if: runner.os != 'Windows'
100102
run: |
101103
cd cpp/build && CTEST_OUTPUT_ON_FAILURE=TRUE make test ARGS="--output-on-failure"
104+
- name: Publish Error
105+
if: always()
106+
uses: actions/upload-artifact@v4
107+
with:
108+
name: build-x64-linux-dbg-err.log
109+
path: /home/runner/work/WeDPR-Component/WeDPR-Component/vcpkg/buildtrees/gsasl/build-x64-linux-dbg-err.log
110+
102111

103112
build_centos:
104113
name: build_centos full node
105-
runs-on: ${{ matrix.os }}
114+
runs-on: ubuntu-latest
106115
continue-on-error: true
107116
strategy:
108117
fail-fast: false
109118
matrix:
110-
os: [ubuntu-latest]
119+
container:
120+
- centos-7.9
111121
container:
112122
image: docker.io/centos:7
113123
volumes:
114124
- /usr/local/share/vcpkg:/usr/local/share/vcpkg
125+
- /node20217:/node20217:rw,rshared
126+
- ${{ matrix.container == 'centos-7.9' && '/node20217:/__e/node20:ro,rshared' || ' ' }}
115127
steps:
116-
- uses: actions/checkout@v3
117-
with:
118-
fetch-depth: 5
128+
- name: install nodejs20glibc2.17
129+
if: ${{ matrix.container == 'centos-7.9' }}
130+
run: |
131+
curl -LO https://unofficial-builds.nodejs.org/download/release/v20.9.0/node-v20.9.0-linux-x64-glibc-217.tar.xz
132+
tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217
133+
- name: Check out the repo
134+
uses: actions/checkout@v4
119135
- uses: actions/cache@v3
120136
id: deps_cache
121137
with:
@@ -148,6 +164,10 @@ jobs:
148164
with:
149165
toolchain: nightly-2022-07-28
150166
override: true
167+
- name: Prepare vcpkg
168+
if: runner.os != 'Windows'
169+
uses: friendlyanon/setup-vcpkg@v1
170+
with: { committish: 51b14cd4e1230dd51c11ffeff6f7d53c61cc5297 }
151171
- name: Check disk space
152172
run: df . -h
153173
- name: Free disk space
@@ -169,7 +189,7 @@ jobs:
169189
rm -rf python
170190
mkdir -p cpp/build
171191
cd cpp/build
172-
cmake3 -DBUILD_STATIC=ON -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
192+
cmake3 -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DBUILD_STATIC=ON -DCMAKE_BUILD_TYPE=Release -DTESTS=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
173193
- name: FreeDiskSpace
174194
run: |
175195
df -lh

.github/workflows/cpp_sdk_workflow.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ concurrency:
2222
env:
2323
RUST_BACKTRACE: 1
2424
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
25+
ACTIONS_RUNNER_FORCED_INTERNAL_NODE_VERSION: node16
26+
ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION: node16
2527

2628
jobs:
2729
build_sdk:
@@ -105,20 +107,27 @@ jobs:
105107

106108
build_centos_for_sdk:
107109
name: build_centos_for_sdk
108-
runs-on: ${{ matrix.os }}
110+
runs-on: ubuntu-latest
109111
continue-on-error: true
110112
strategy:
111113
fail-fast: false
112114
matrix:
113-
os: [ubuntu-latest]
115+
container:
116+
- centos-7.9
114117
container:
115118
image: docker.io/centos:7
116119
volumes:
117120
- /usr/local/share/vcpkg:/usr/local/share/vcpkg
121+
- /node20217:/node20217:rw,rshared
122+
- ${{ matrix.container == 'centos-7.9' && '/node20217:/__e/node20:ro,rshared' || ' ' }}
118123
steps:
119-
- uses: actions/checkout@v3
120-
with:
121-
fetch-depth: 5
124+
- name: install nodejs20glibc2.17
125+
if: ${{ matrix.container == 'centos-7.9' }}
126+
run: |
127+
curl -LO https://unofficial-builds.nodejs.org/download/release/v20.9.0/node-v20.9.0-linux-x64-glibc-217.tar.xz
128+
tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217
129+
- name: Check out the repo
130+
uses: actions/checkout@v4
122131
- uses: actions/cache@v3
123132
id: deps_cache
124133
with:
@@ -149,11 +158,15 @@ jobs:
149158
yum install -y java-11-openjdk-devel git make gcc gcc-c++ glibc-static glibc-devel openssl cmake3 ccache devtoolset-11 llvm-toolset-7.0 rh-perl530-perl libzstd-devel zlib-devel flex bison python-devel python3-devel
150159
yum install -y rh-perl530-perl cmake3 zlib-devel ccache lcov python-devel python3-devel
151160
yum install -y git
161+
- name: Prepare vcpkg
162+
if: runner.os != 'Windows'
163+
uses: friendlyanon/setup-vcpkg@v1
164+
with: { committish: 51b14cd4e1230dd51c11ffeff6f7d53c61cc5297 }
152165
- name: Build
153166
run: |
154167
alias cmake='cmake3'
155168
. /opt/rh/devtoolset-11/enable
156169
mkdir -p cpp/build
157170
cd cpp/build
158-
cmake3 -DCMAKE_BUILD_TYPE=Release -DBUILD_SDK=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
171+
cmake3 -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SDK=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
159172
cmake3 --build . --parallel 3

.github/workflows/cpp_toolkit_workflow.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ concurrency:
2222
env:
2323
RUST_BACKTRACE: 1
2424
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
25+
ACTIONS_RUNNER_FORCED_INTERNAL_NODE_VERSION: node16
26+
ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION: node16
2527

2628
jobs:
2729
build_wedpr_toolkit:
@@ -111,20 +113,27 @@ jobs:
111113

112114
build_centos_for_toolkit:
113115
name: build_centos_for_toolkit
114-
runs-on: ${{ matrix.os }}
116+
runs-on: ubuntu-latest
115117
continue-on-error: true
116118
strategy:
117119
fail-fast: false
118120
matrix:
119-
os: [ubuntu-latest]
121+
container:
122+
- centos-7.9
120123
container:
121124
image: docker.io/centos:7
122125
volumes:
123126
- /usr/local/share/vcpkg:/usr/local/share/vcpkg
127+
- /node20217:/node20217:rw,rshared
128+
- ${{ matrix.container == 'centos-7.9' && '/node20217:/__e/node20:ro,rshared' || ' ' }}
124129
steps:
125-
- uses: actions/checkout@v3
126-
with:
127-
fetch-depth: 5
130+
- name: install nodejs20glibc2.17
131+
if: ${{ matrix.container == 'centos-7.9' }}
132+
run: |
133+
curl -LO https://unofficial-builds.nodejs.org/download/release/v20.9.0/node-v20.9.0-linux-x64-glibc-217.tar.xz
134+
tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217
135+
- name: Check out the repo
136+
uses: actions/checkout@v4
128137
- uses: actions/cache@v3
129138
id: deps_cache
130139
with:
@@ -155,13 +164,17 @@ jobs:
155164
yum install -y java-11-openjdk-devel git make gcc gcc-c++ glibc-static glibc-devel openssl cmake3 ccache devtoolset-11 llvm-toolset-7.0 rh-perl530-perl libzstd-devel zlib-devel flex bison python-devel python3-devel
156165
yum install -y rh-perl530-perl cmake3 zlib-devel ccache lcov python-devel python3-devel
157166
yum install -y git
167+
- name: Prepare vcpkg
168+
if: runner.os != 'Windows'
169+
uses: friendlyanon/setup-vcpkg@v1
170+
with: { committish: 51b14cd4e1230dd51c11ffeff6f7d53c61cc5297 }
158171
- name: Build
159172
run: |
160173
alias cmake='cmake3'
161174
. /opt/rh/devtoolset-11/enable
162175
mkdir -p cpp/build
163176
cd cpp/build
164-
cmake3 -DCMAKE_BUILD_TYPE=Release -DBUILD_WEDPR_TOOLKIT=ON -DBUILD_PYTHON=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
177+
cmake3 -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_WEDPR_TOOLKIT=ON -DBUILD_PYTHON=ON -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake ../
165178
cmake3 --build . --parallel 3
166179
- uses: actions/upload-artifact@v3
167180
with:

cpp/cmake/CompilerSettings.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ endif()
197197

198198
# rust static library linking requirements for macos
199199
if(APPLE)
200-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Security")
200+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Security -framework Kerberos")
201201
else()
202202
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ldl")
203203
endif()

cpp/cmake/TargetSettings.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ set(AIR_BINARY_NAME ppc-air-node)
8787
set(CEM_BINARY_NAME wedpr-cem)
8888
set(MPC_BINARY_NAME wedpr-mpc)
8989

90-
set(HDFS_LIB libhdfs3-static)
90+
set(HDFS_LIB libhdfs3)
9191

9292
# set cpu-info
9393
set(CPU_FEATURES_LIB "")
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (C) 2022 WeDPR.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* @file Krb5AuthConfig.h
17+
* @author: yujiechen
18+
* @date 2024-12-2
19+
*/
20+
#pragma once
21+
#include "ppc-framework/Common.h"
22+
#include <memory>
23+
#include <sstream>
24+
#include <string>
25+
26+
namespace ppc::protocol
27+
{
28+
struct Krb5AuthConfig
29+
{
30+
using Ptr = std::shared_ptr<Krb5AuthConfig>;
31+
std::string principal;
32+
std::string password;
33+
std::string ccachePath;
34+
std::string authConfigFilePath = "./conf/krb5.conf";
35+
void check() const
36+
{
37+
if (principal.size() == 0)
38+
{
39+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
40+
"Invalid krb5 auth config: Must set the principal!"));
41+
}
42+
if (password.size() == 0)
43+
{
44+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
45+
"Invalid krb5 auth config: Must set the password!"));
46+
}
47+
if (ccachePath.size() == 0)
48+
{
49+
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
50+
"Invalid krb5 auth config: Must set the ccachePath!"));
51+
}
52+
if (authConfigFilePath.size() == 0)
53+
{
54+
BOOST_THROW_EXCEPTION(
55+
WeDPRException() << bcos::errinfo_comment(
56+
"Invalid krb5 auth config: Must set the authConfigFilePath!"));
57+
}
58+
}
59+
60+
inline std::string desc() const
61+
{
62+
std::stringstream oss;
63+
oss << LOG_KV("principal", principal) << LOG_KV("ccachePath", ccachePath)
64+
<< LOG_KV("authConfigFilePath", authConfigFilePath);
65+
return oss.str();
66+
}
67+
};
68+
} // namespace ppc::protocol

cpp/ppc-framework/protocol/Protocol.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define WIN32_LEAN_AND_MEAN
2424
#include <windows.h>
2525
#endif
26+
#include "Krb5AuthConfig.h"
2627
#include "ppc-framework/Common.h"
2728
#include <bcos-utilities/Log.h>
2829
#include <map>
@@ -452,6 +453,7 @@ struct FileStorageConnectionOption
452453
bool replaceDataNodeOnFailure = false;
453454
// the default connection-timeout for the hdfs is 1000ms
454455
uint16_t connectionTimeout = 1000;
456+
Krb5AuthConfig::Ptr authConfig;
455457

456458
void check() const
457459
{
@@ -470,14 +472,19 @@ struct FileStorageConnectionOption
470472
BOOST_THROW_EXCEPTION(WeDPRException() << bcos::errinfo_comment(
471473
"Invalid HDFS Option, Must set valid namenodeport!"));
472474
}
475+
if (authConfig)
476+
{
477+
authConfig->check();
478+
}
473479
}
474480
inline std::string desc() const
475481
{
476482
std::stringstream oss;
477483
oss << LOG_KV("nameNode", nameNode) << LOG_KV("nameNodePort", nameNodePort)
478484
<< LOG_KV("user", userName) << LOG_KV("token", token)
479485
<< LOG_KV("replace-datanode-on-failure", replaceDataNodeOnFailure)
480-
<< LOG_KV("connectionTimeout", connectionTimeout);
486+
<< LOG_KV("connectionTimeout", connectionTimeout)
487+
<< LOG_KV("authInfo", authConfig ? authConfig->desc() : "null");
481488
return oss.str();
482489
}
483490
};

cpp/tools/build_ppc.sh

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,24 @@ generate_node_config_ini() {
476476
477477
[hdfs_storage]
478478
; the hdfs configuration
479-
user = app
479+
user = root
480480
name_node = 127.0.0.1
481481
name_node_port = 9000
482482
token =
483483
; enable replace-datanode-on-failure or not
484484
replace-datanode-on-failure = false
485485
; the connection-timeout, in ms, default is 1000ms
486486
connection-timeout = 1000
487+
; enable auth or not, default is false
488+
; enable_krb5_auth = false
489+
; the hdfs kerberos auth principal, used when enable_krb5_auth
490+
; auth_principal = [email protected]
491+
; the hdfs kerberos auth password, used when enable_krb5_auth
492+
; auth_password =
493+
; the ccache path, used when enable_krb5_auth
494+
; ccache_path = /tmp/krb5cc_ppc_node
495+
; the krb5.conf path
496+
; krb5_conf_path = conf/krb5.conf
487497
488498
489499
[ra2018psi]
@@ -541,6 +551,31 @@ generate_node_config_ini() {
541551
EOF
542552
}
543553

554+
generate_krb5_file_template()
555+
{
556+
local filepath=$1
557+
mkdir -p $(dirname $filepath)
558+
cat << EOF > "${filepath}"
559+
[libdefaults]
560+
default_realm = NODE.DC1.CONSUL
561+
dns_lookup_realm = false
562+
dns_lookup_kdc = false
563+
ticket_lifetime = 24h
564+
renew_lifetime = 7d
565+
forwardable = true
566+
567+
[realms]
568+
NODE.DC1.CONSUL = {
569+
kdc =
570+
admin_server =
571+
}
572+
573+
[domain_realm]
574+
.node.dc1.consul = NODE.DC1.CONSUL
575+
node.dc1.consul = NODE.DC1.CONSUL
576+
EOF
577+
}
578+
544579
generate_script_template()
545580
{
546581
local filepath=$1
@@ -915,6 +950,7 @@ deploy_nodes()
915950
private_key=$(generate_private_key "${node_dir}/conf")
916951
node_id=$(cat "${node_dir}/conf/node.nodeid")
917952
generate_node_config_ini "${node_dir}/config.ini" "${listen_ip}" "${gateway_port}" "${listen_ip}" "${rpc_port}" "${listen_ip}" "${grpc_port}" ${agency_id} "${count}" "${node_id}"
953+
generate_krb5_file_template "${node_dir}/conf/krb5.conf"
918954
generate_p2p_connected_conf "${node_dir}/${p2p_connected_conf_name}" "${connected_nodes}" "false"
919955
set_value ${ip//./}_count $(($(get_value ${ip//./}_count) + 1))
920956
((++count))

0 commit comments

Comments
 (0)